How to override default attributes in Chef using roles -


i can't work, been @ hours. there's duplicate of question here, never adequately answered. i've tried strip problem down minimum.

here's trivial recipe: "my_recipe.rb"

file "/tmp/my_target_file"   content node.default['my_file_content']   action :create end 

...and attributes file in attributes subdirectory: "my_attribute.rb"

default['my_file_content'] = 'from my_attribute.rb' 

i create role in roles subdirectory: "my_role.rb"

name 'my_role' description 'my role' run_list 'recipe[my_cookbook::my_recipe]' default_attributes['my_file_content'] = 'from my_role.rb' 

i upload both cookbook , role chef server , run knife command chef workstation:

knife bootstrap xxx.xxx.xxx.xxx -x myusername -p mysudopassword --sudo -r role[my_role] -n my_node_name 

it runs fine , target file gets created, contents of /tmp/my_target_file not expected. i'm getting

$ cat /tmp/my_target_file my_attribute.rb 

... of course wanted was

$ cat /tmp/my_target_file my_role.rb 

according chef attributes precedence, http://docs.chef.io/attributes.html, should have worked. i've tried using 'override_attributes' same result. if login chef server , drill down attributes of node, can see attribute

my_file_content: my_role.rb 

along other ohai generated ones.

there i'm not getting here. can please explain how override attributes using roles?

file "/tmp/my_target_file"   content node.default['my_file_content']   action :create end 

node.default method call on node object aimed update value of ['my_file_content'] attribute in recipe.

it should not used value you're getting value @ default recipe level (i.e: attributes files) , not resulting value attribute precedence.

instead use node['my_file_content'] way ask value of my_file_content attribute resulting different lelvel of precendence.

use , work:

file "/tmp/my_target_file"   content node['my_file_content']   action :create end 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -