[RESOLVED] One time runlist during bootstrap


#1

I feel like this has been asked before, but I can’t seem to find the answer I am looking for, or in fact an answer (even if it isn’t what I want to hear).

I have a cookbook that does organisation specific config of our nodes during bootstrap. I am wanting to know if there is a way to supply a one time runlist during bootstrap so that the initial runlist specified isn’t permanent? I see there used to be a -o option that could be used as an override, but the knife bootstrap command doesn’t like this anymore :frowning:

Thanks for your help in advance!


#2

This is most commonly done by having the cookbook you use during bootstrap modify the run list.


#3

So, interestingly, having the cookbook do it, is not working. I can see the command runs as expected, within the cookbook with out any issues.

Here is the output of the batch resource ``

batch[remove_bootstrap_runlist] action run[2017-03-15T10:37:37+13:00] INFO: Processing 
batch[remove_bootstrap_runlist] action run (mycookbook::default line 69)

    [execute]
              C:\>knife node run_list remove windows-test-01 'recipe[mycookbook]' -c c:\chef\client.rb
              windows-test-01:
                run_list:
    [2017-03-15T10:37:40+13:00] INFO: batch[remove_mycookbook_runlist] ran successfully

Here is the batch resource I am trying to use within the cookbook.

  batch 'remove_bootstrap_runlist' do
    code <<-EOH
      knife node run_list remove #{nodename} 'recipe[mycookbook]' -c c:\\chef\\client.rb
    EOH
  end

Now, if I run the batch resource from the node’s cmd independent of the cookbook using knife, it all runs as expected and edits the nodes run_list

knife node run_list remove windows-test-01 'recipe[mycookbook]' -c c:\\chef\\client.rb

Here are the server/client versions I am using.
chef-server 12.12
Chef-client 12.19.36


#4

This won’t work. knife will successfully edit the node, but then when the in-progress Chef Client run completes, it will save the node and overwrite what knife did.

What you want to do instead is modify the run list on the node object in Chef Client so that the run list you want gets saved by Chef at the end of the run. The basic code is node.run_list("recipe[foo::bar]", "recipe[baz::qux]", ...) though you may need to stuff that in a ruby block resource to get the compile time/converge time stuff right, depending on how you compute the run list.


#5

Thanks for that. Here is what I ended up doing, just incase another noob (like me) requires a more full answer:

# Removes the recipe 'my_recipe' from the nodes run list
ruby_block 'remove_my_recipe' do
  block do
    node.run_list.remove('recipe[my_recipe]')
  end
  action :run
end

#6

Thanks for sharing this helped me!