# Chef-Solo: set the node attribute to an arbitrary value

**URL:** <https://discourse.chef.io/t/chef-solo-set-the-node-attribute-to-an-arbitrary-value/6378>\
**Category:** Chef Infra (archive)\
**Created:** [March 6, 2015, 8:52pm UTC](https://discourse.chef.io/t/chef-solo-set-the-node-attribute-to-an-arbitrary-value/6378 "2015-03-06T20:52:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shubby](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@Shubby](https://discourse.chef.io/u/Shubby)\
**Post date:** [March 6, 2015, 8:52pm UTC](https://discourse.chef.io/t/chef-solo-set-the-node-attribute-to-an-arbitrary-value/6378/1 "2015-03-06T20:52:18Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jdunn](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/jdunn/32/1800_2.png) [@jdunn](https://discourse.chef.io/u/jdunn)\
**Post date:** [March 6, 2015, 10:28pm UTC](https://discourse.chef.io/t/chef-solo-set-the-node-attribute-to-an-arbitrary-value/6378/2 "2015-03-06T22:28:23Z")

</div>

I think per the Vagrant documentation you are going to want

chef.environment = 'whatever'

> **[Chef Solo - Provisioning | Vagrant | HashiCorp Developer](https://developer.hashicorp.com/vagrant/docs/provisioning/chef_solo)**
>
> The Vagrant Chef Solo provisioner allows you to provision the guest using
> Chef, specifically with chef-solo.

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  
[fabien.delpierre@gmail.com](mailto:fabien.delpierre@gmail.com) 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 [jdunn@aquezada.com](mailto:jdunn@aquezada.com) \* Sorry, I'm ]  
[WWW: [Julian Dunn's Blog - Commentary on media, technology, and everything in between.](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]

---

<div class="post-metadata">

**Author:** ![Shubby](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@Shubby](https://discourse.chef.io/u/Shubby)\
**Post date:** [March 10, 2015, 4:55pm UTC](https://discourse.chef.io/t/chef-solo-set-the-node-attribute-to-an-arbitrary-value/6378/3 "2015-03-10T16:55:34Z")

</div>

Alright, guess I'm stuck having to have real environments. That's alright  
as I will have them in prod, it was just easier for dev to try and tell  
Chef that the environment is 'x' even when 'x' isn't a real environment.  
Thanks!

On Fri, Mar 6, 2015 at 5:28 PM, Julian C. Dunn [jdunn@aquezada.com](mailto:jdunn@aquezada.com) wrote:

> I think per the Vagrant documentation you are going to want
> 
> chef.environment = 'whatever'
> 
> [Chef Solo - Provisioning | Vagrant | HashiCorp Developer](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  
> [fabien.delpierre@gmail.com](mailto:fabien.delpierre@gmail.com) 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 [jdunn@aquezada.com](mailto:jdunn@aquezada.com) \* Sorry, I'm ]  
> [WWW: [Julian Dunn's Blog - Commentary on media, technology, and everything in between.](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]
