I want to change my attribute value dynamically during run time .
Ex. attribute: foo: ‘Hello’ Now I want to change value of key ‘foo’ to ‘World’.
So is there any way to do that? Please help.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.
In Chef, you can certainly change attribute values during runtime. You can do this using the node.override['attribute_name'] in your recipe code.
For example, if you want to change ‘foo’ to ‘World’, you could use:
- ruby node.override['foo'] = 'World'
After this line of code, whenever you access node['foo'] in the same Chef run, it will return ‘World’ instead of ‘Hello’.
Remember, this will only affect the current Chef run. If you want the changed value to persist, you will need to save the node at the end of the chef run.
Note: Overriding attributes in Chef should be used sparingly, as it can lead to difficult-to-debug situations because of the way Chef attribute precedence levels work.
For more information about Chef attributes, please check out the official Chef documentation.
Hope that this helps!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.