matschaffer / knife-solo

DEPRECATED: Please consider using https://knife-zero.github.io/, ansible, or visit https://www.chef.io/ for other ideas
MIT License
787 stars 213 forks source link

Setting attributes in node or role file not working #479

Closed jbwyatt4 closed 8 years ago

jbwyatt4 commented 8 years ago

Hello,

I've attached a role to demonstrate (.txt was added because github didn't like a json file). I test for the attributes in the recipe with:

p node.override p node.attribute?("r_version")

I keep getting false or nil every time.

ubuntu-rails-app-server.json.txt

Using knife-solo 0.5.1

matschaffer commented 8 years ago

The chef solo json files don't take default/overrides like this since they're always the final override on top of everything else.

See https://docs.chef.io/chef_solo.html for details. Specifically the "Attributes" section and the warning section where --json-attributes is covered.

Hope that helps!

jbwyatt4 commented 8 years ago

I'm afraid I don't understand it that well. How would I override a normal attribute using the node or role file with chef-solo?

matschaffer commented 8 years ago

Node is different than role. Node would be {"attribute_name": "attribute_value"} at the top level of the JSON hash. For a role I'd recommend using a .rb role and a default_attributes call like the one shown in https://docs.chef.io/roles.html (e.g., default_attributes attribute_name: "attribute_value")

jbwyatt4 commented 8 years ago

Thankyou! Got it working.

matschaffer commented 8 years ago

:+1: