How to update node run_list using knife, during convergence

1k Views Asked by At

We have given scenario below,

  • Our node has run_list with "role a" and "role b". Node gets converged and runs the run_list.
  • During the node convergence run in step 1, we are trying to add another "role c" to the node run_list, using knife command. It is successfully added as per the knife command output.
  • If we check the knife node status, after the node convergence finished. The "role c", we added in step 2 has not been added to node run_list

How to update node run_list using knife command, during node convergence run?

1

There are 1 best solutions below

5
On BEST ANSWER

Knife commands are aimed at being used on a workstation to manage the chef-server. They MUST not be used inside recipes to change the behavior (as this won't work).

What happens here:

  • Within the chef-run, someone (even not the node itself) change the node object and modify its run_list.

  • When the node ends its run, it saves back the node object (including the runlist) and overwrite what has been done meanwhile, your knife command is of no use.

If you wish to change the run_list withing a recipe you should use the node.run_list method which will allow to modify the run_list for the future runs.

Given your exemple your could use:

ruby_block 'remove ntp::undo from run list' do
  block do
    node.run_list.add('role[role c]')
  end
  only_if { !node.run_list.include?('role[role c]') }
end