Skip to content

Instantly share code, notes, and snippets.

@StFS
Created December 22, 2014 17:41
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 StFS/2a333afe352d0dc8cbb5 to your computer and use it in GitHub Desktop.
Save StFS/2a333afe352d0dc8cbb5 to your computer and use it in GitHub Desktop.
Chef attribute file problem
default["rda"]["user"] = 'rda'
default['rda']['home_dir'] = "/home/#{node.rda.user}"
raise node.rda.inspect
default['rda']['home_env_dir'] = "#{node.rda.home_dir}/env/dev"
# This throws a runtime error (due to the 'raise' line) with the output: {"user"=>"rda"}
# So it never adds anything after attempting to create the rda.home_dir value
# but Chef does not throw an error itself, it only happens because I have a raise in there.
#----------------
# So I tried to move the 'raise' line down one line:
default["rda"]["user"] = 'rda'
default['rda']['home_dir'] = "/home/#{node.rda.user}"
default['rda']['home_env_dir'] = "#{node.rda.home_dir}/env/dev"
raise node.rda.inspect
# This results in the error: Undefined method or attribute `home_dir' on `node'
# so the execution now never reaches the 'raise' line.
#----------------
# So now I tried hard coding all values instead of depending on previous attributes:
default["rda"]["user"] = 'rda'
default['rda']['home_dir'] = "/home/rda"
default['rda']['home_env_dir'] = "/home/rda/env/dev"
raise node.rda.inspect
# This appears normal. Of course the 'raise' results in an error but the message
# I get is an attribute map that I was expecting:
# {"user"=>"rda", "home_dir"=>"/home/rda", "home_env_dir"=>"/home/rda/env/dev"}
# If I remove the raise line, the execution continues until it encounters the next
# attribute that depends on an attribute that depends on an attribute!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment