[chef] Chef-Solo: set the node['chef_environment'] attribute to an arbitrary value


Chronological Thread 
  • From: Fabien Delpierre < >
  • To: chef < >
  • Subject: [chef] Chef-Solo: set the node['chef_environment'] attribute to an arbitrary value
  • Date: Fri, 6 Mar 2015 15:52:18 -0500

Hello folks,
I'm trying to make my Vagrant VM assume that node.chef_environment = something, even though that "something" is not an environment that actually exists (i.e. I don't have an environments/something.rb).

So in my Vagrantfile, I have the following:
config.vm.provision :chef_solo do |chef|
  chef.json = {
    chef_environment: 'foo_vagrant'
  }
  chef.run_list = [
    'recipe[foo::default]'
  ]
end


I did it that way because I don't know any better, and in the past I've written cookbooks with case statements reading the node.chef_environment attribute and setting other attributes one way or another depending on what the environment is. However, I did have actual environment files then. So perhaps my attempt at cleverness failed.

Anyway, I also have the following bit of recipe code:
cookbook_file '/etc/init.d/celery_worker' do
  source "#{node.chef_environment}_celery_worker"
  mode '0755'
  action :nothing
end.run_action(:create)

Sadly, when my recipe runs, I get the following:
==> default: Error executing action `create` on resource 'cookbook_file[/etc/init.d/celery_worker]'
==> default: ================================================================================
==> default:
==> default: Chef::Exceptions::FileNotFound
==> default: ------------------------------
==> default: Cookbook 'foo' (0.9.2) does not contain a file at any of these locations:
==> default:   files/centos-6.6/_default_celery_worker
==> default:   files/centos/_default_celery_worker
==> default:   files/default/_default_celery_worker
==> default:   files/_default_celery_worker


So I totally get that the _default environment was applied to my node instead of what I had hoped to force through the Vagrantfile. And so my question is... what, if anything, can I do about this, short of actually having an environment file? If it makes a difference, I don't have a requirement to use Chef-Solo, I could switch to Chef-Zero, I just chose Chef-Solo for this project because I've never looked at Chef-Zero yet.

Thanks!



Archive powered by MHonArc 2.6.16.

§