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


Chronological Thread 
  • From: "Julian C. Dunn" < >
  • To: " " < >
  • Subject: [chef] Re: Chef-Solo: set the node['chef_environment'] attribute to an arbitrary value
  • Date: Fri, 6 Mar 2015 16:28:23 -0600

I think per the Vagrant documentation you are going to want

  chef.environment = 'whatever'

http://docs.vagrantup.com/v2/provisioning/chef_solo.html

You'll also need to provide an environment path that contains a JSON
file representing the environment.

- Julian

On Fri, Mar 6, 2015 at 2:52 PM, Fabien Delpierre
< >
 wrote:
> 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!



-- 
[ Julian C. Dunn 
< >
          * Sorry, I'm    ]
[ WWW: http://www.aquezada.com/staff/julian    * only Web 1.0  ;]
gopher://sdf.org/1/users/keymaker/           * compliant!    ;]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9       ]



Archive powered by MHonArc 2.6.16.

§