chef - When automatic attributes(Ohai data) get update? -
from introduction of http://docs.opscode.com/chef_overview_attributes.html#automatic-ohai, says "an automatic attribute contains data identified ohai at beginning of every chef-client run. automatic attribute cannot modified , has highest attribute precedence."
from understanding:
- automatic attributes cannot modified.
- automatic attributes updated when chef-client runs
for number 1, it's not true. i'm able modify automatic attribute. instance, change version of chef package:
require 'chef' chef::config.from_file(file.join('/home/chefuser', '.chef', 'knife.rb')) query = chef::search::query.new # search node node name, test_machine in case nodes = query.search('node', "name:test_machine").first nodes[0].automatic["chef_packages"]["chef"]["version"] = "11.12.2" nodes[0].save
and using
knife node show test_machine -l | grep version
the version of chef package has been changed. question: right way modify automatic attributes? or not necessary change automatic attributes, because ohai automatically?
for number 2, question: mean "at beginning of chef-client run"? automatic attributes never updated if chef-client not run?
i suppose automatic attributes should updated once system configuration being changed. i'm wondering when automatic attributes updated without running chef-client.
automatic attributes can't modified in context of chef client run. if set attribute on saved node object (which code doing), reset @ start of every chef client run , value ohai override it.
here's rough sequence of events during chef client run:
- chef retrieves saved node object chef server (if 1 exists)
- it applies attribute overrides cookbooks/roles/recipes
- it applies automatic attributes provided ohai
- it executes run list using updated state
- it saves updated node object on chef server if run succeeded
so if need correct automatic attributes within chef-client run, don't have since happens automatically.
edit: can find more details attribute persistence , precedence here.
Comments
Post a Comment