YggdrasillNetwork Blog

A blogging framework for hackers.

Vagrant の Provisioner に Chef Client を利用する際に遭遇したトラブルとその解決策

概要

Vagrant の Provisioner に Chef Client を利用する際に遭遇したトラブルとその解決策

内容

Hosted Chef を Chef Server として利用し、下記の設定がされている状態で、vagrant destory を実行すると VM は削除されるが、Hosted Chef 上の Nodes/Clients から情報が削除されない。

1
2
3
4
5
6
7
chef.chef_server_url = "https://api.opscode.com/organizations/tech-sales"
chef.validation_client_name = "tech-sales-validator"
chef.validation_key_path = "../../hosted-chef-repo/.chef/tech-sales-validator.pem"
chef.environment = "setup"
chef.node_name = "chef-test"
chef.delete_node = true
chef.delete_client = true

エラーログ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
==> default: Running cleanup tasks for 'chef_client' provisioner...
==> default: Deleting client "chef-test" from Chef server...
==> default: Cleaning up the 'client' for Chef failed. The stdout and
==> default: stderr are shown below. Vagrant will continue destroying the machine,
==> default: so please clean up these resources manually.
==> default: 
==> default: stdout: Response: Cannot load client chef-test
==> default: 
==> default: 
==> default: stderr: ERROR: The object you are looking for could not be found
==> default: Deleting node "chef-test" from Chef server...
==> default: Cleaning up the 'node' for Chef failed. The stdout and
==> default: stderr are shown below. Vagrant will continue destroying the machine,
==> default: so please clean up these resources manually.
==> default: 
==> default: stdout: Response: node 'chef-test' not found
==> default: 
==> default: 
==> default: stderr: ERROR: The object you are looking for could not be found

対応策

未解決

chef is not part of the bundle エラー

内容

下記の設定がされている状態で、vagrant destory を実行すると VM は削除されるが、chef server 上の Nodes/Clients から情報が削除されない。

1
2
chef.node_name = "vagrant-win7"
chef.delete_node = true

chef is not part of the bundle. Add it to Gemfile. (Gem::LoadError) のエラーを吐いて処理が終了してしまう。

エラーログ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$ vagrant destroy -f
WARNING: Could not load IOV methods. Check your GSSAPI C library for an update
WARNING: Could not load AEAD methods. Check your GSSAPI C library for an update
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
==> default: Running cleanup tasks for 'chef_client' provisioner...
==> default: Deleting client "vagrant-win7.example.local" from Chef server...
==> default: Cleaning up the 'client' for Chef failed. The stdout and
==> default: stderr are shown below. Vagrant will continue destroying the machine,
==> default: so please clean up these resources manually.
==> default: 
==> default: stdout: 
==> default: 
==> default: stderr: /Applications/Vagrant/embedded/gems/gems/bundler-1.6.2/lib/bundler/rubygems_integration.rb:252:in `block in replace_gem': chef is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
==> default:   from /Users/ryo/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/bin/knife:22:in `<main>'
==> default:   from /Users/ryo/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `eval'
==> default:   from /Users/ryo/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `<main>'
==> default: Deleting node "vagrant-win7.example.local" from Chef server...
==> default: Cleaning up the 'node' for Chef failed. The stdout and
==> default: stderr are shown below. Vagrant will continue destroying the machine,
==> default: so please clean up these resources manually.
==> default: 
==> default: stdout: 
==> default: 
==> default: stderr: /Applications/Vagrant/embedded/gems/gems/bundler-1.6.2/lib/bundler/rubygems_integration.rb:252:in `block in replace_gem': chef is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
==> default:   from /Users/ryo/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/bin/knife:22:in `<main>'
==> default:   from /Users/ryo/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `eval'
==> default:   from /Users/ryo/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `<main>'

対応策

Vagrant の Version を 1.6.5 に上げる

Vagrant 1.6.3 だとエラーが出るが、 1.6.5 だとエラーが出ず、Chef Server 上から Nodes/Clients から情報が削除される。

NameError

内容

下記の設定がされている状態で、vagrant destory を実行すると VM は削除されるが、chef server 上の Nodes/Clients から情報が削除されない。

1
chef.delete_node = true

uninitialized constant Berkshelf::BerkshelfError (NameError) のエラーを吐いて処理が終了してしまう。

エラーログ

1
2
3
4
5
6
7
8
9
$ vagrant destroy -f

WARNING: Could not load IOV methods. Check your GSSAPI C library for an update
WARNING: Could not load AEAD methods. Check your GSSAPI C library for an update
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
==> default: Running cleanup tasks for 'chef_client' provisioner...
==> default: Deleting client "" from Chef server...
/Users/ryo/.vagrant.d/gems/gems/vagrant-berkshelf-3.0.1/lib/berkshelf/vagrant/action/clean.rb:21:in `rescue in call': uninitialized constant Berkshelf::BerkshelfError (NameError)

対応策

Chef Server 上のどの Node を削除するのか指定できないので、エラーで止まるみたい。

Vagrantfile に下記の記述を追加して対応

1
chef.node_name = "vagrant-win7"