Skip to content

Instantly share code, notes, and snippets.

@patmaddox
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patmaddox/9633594 to your computer and use it in GitHub Desktop.
Save patmaddox/9633594 to your computer and use it in GitHub Desktop.
<srbaker>SOLVED</srbaker>
default_attributes chef_user: "ubuntu"
default_attributes { ... a whole mess of other stuff which apparently blows away the first line. whoops }
when recipes_rbenv.rb is loaded, node['chef_user'] is nil. However I can see a
chef_user attribute if I look at the node information on the chef server. I've
also tried passing {'chef_user' => 'ubuntu'} to default_attributes in case it
was a problem with string vs symbol for the key. No luck. Any ideas how I can
get the value of this attribute that's set in the environment's default_attributes?
node.default['rbenv']['user_installs'] = [
{'user' => node['chef_user'] }
]
@fujin
Copy link

fujin commented Mar 19, 2014

try out 'log node.debug_value(:chef_user)' or similar.

@fujin
Copy link

fujin commented Mar 19, 2014

I would guess that the recipe compile time is evaluating before the attributes from the environment are available for some reason, although that's not obvious according to the attribute precedence page. sorry~ :)

is there some reason you can't have this in an attributes file?

default['rbenv']['user_installs']['user'] = node['chef_user'] if node.key? 'chef_user'

Or simply specify rbenv.user_installs.user in your environment dsl? :)

@patmaddox
Copy link
Author

thanks for the reply @fujin

well I reference chef_user a bunch of places, including in my own templates. I'm pretty confused because I thought this worked just fine when I did a knife bootstrap and along with a couple other chef-client updates, but now it's not working. I'm under the impression that chef can't / shouldn't just stop working like that so I'm not really sure what's going on.

But anyway yeah there are like 15 references to chef_user in other recipes, so I do need to sort out how to get the recipe to read the attribute as set in the environment.

@patmaddox
Copy link
Author

here's what I get when I include puts node.debug_value(:chef_user) in the recipe. Not sure what I'm looking for to tell you the truth…

set_unless_enabled?
false
default
not_present
env_default
not_present
role_default
not_present
force_default
not_present
normal
not_present
override
not_present
role_override
not_present
env_override
not_present
force_override
not_present
automatic
not_present

@patmaddox
Copy link
Author

okay got it sorted, you can't call default_attributes twice in an environment file, the second call will blow away the first one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment