I have an existing chef-solo
project to which I am trying to add vagrant
support. I typically use knife to cook these recipes on EC2 servers using Ubuntu 10.04 AMIs published by Canonical.
Vagrant requires that I add chef_type
and json_class
attributes to my working roles/*.json
files, like this:
{
"name": "memcached",
"chef_type": "role",
"json_class": "Chef::Role",
"run_list": ["base", "memcached"]
}
If I don't add these to the role definition file, then I get this next error. Presumably these attributes tell chef to treat my JSON file like an instance of Chef::Role class.
[default] [Thu, 26 May 2011 02:19:44 +0200] DEBUG: NoMethodError: undefined method `run_list_for' for {"name"=>"memcached", "run_list"=>["wantsa", "memcached"]}:Hash
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/run_list/run_list_expansion.rb:139:in `expand_run_list_items'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/run_list/run_list_expansion.rb:78:in `expand'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/run_list.rb:138:in `expand'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/node.rb:437:in `expand!'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/client.rb:249:in `build_node'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/client.rb:151:in `run'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/application/solo.rb:192:in `run_application'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/application/solo.rb:183:in `loop'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/application/solo.rb:183:in `run_application'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/application.rb:66:in `run'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/chef-solo:25
/opt/ruby/bin/chef-solo:19:in `load'
/opt/ruby/bin/chef-solo:19
However, when I try to cook the same role on EC2 the existence of chef_type
and json_class
attributes break the process, yielding the next error. Presumably this is because in this case chef wants to treat my role definition like a Ruby hash (and call .delete
from it)
/usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/node.rb:379:in `consume_run_list': undefined method `delete' for #<Chef::Role:0x7fa337535138> (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/node.rb:370:in `consume_attributes'
from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/node.rb:358:in `consume_external_attrs'
from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/client.rb:222:in `build_node'
from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/client.rb:145:in `run'
from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/application/solo.rb:190:in `run_application'
from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/application/solo.rb:181:in `loop'
from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/application/solo.rb:181:in `run_application'
from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/application.rb:62:in `run'
from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/chef-solo:25
from /usr/bin/chef-solo:19:in `load'
from /usr/bin/chef-solo:19
rake aborted!
When I remove the chef_type
and json_class
my EC2 cooking scripts go back to working as normal, but then Vagrant is broken.
The main difference that I see between my chef-solo command and the one used by Vagrant is that my chef-solo command has a direct relationship to my roles.json file, while Vagrant's is wrapped up in the dna.json
file.
Mine:
ssh [email protected] "cd /etc/chef; sudo env chef_environment=production chef-solo -l info -c config/solo.rb -j roles/memcached.json "
Vagrants:
cd /tmp/vagrant-chef
chef-solo -c solo.rb -j dna.json
Is there some way that I can configure my Vagrantfile to make these work?
While I haven't run into this particular problem, I have noticed that Chef, as a moving target, tends to have strange stuff happen like this if you're using the same recipes on different versions of Chef.
Just to eliminate that, the first thing I would try is to make my chef versions consistent. I see that your Vagrant VM is using version 0.10.0 and your EC2 VM is using 0.9.16 - whichever is more important, perhaps you could standardize on that one - e.g. if you're trying to replicate your EC2 system locally, you can recreate your Vagrant base box (or look into making your own, the documentation is pretty good on the Vagrant website) such that it more closely matches what you've got installed on EC2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With