Skip to content

Instantly share code, notes, and snippets.

@kam1kaze
Last active November 10, 2015 10:43
Show Gist options
  • Save kam1kaze/5e3622b0574b35bab483 to your computer and use it in GitHub Desktop.
Save kam1kaze/5e3622b0574b35bab483 to your computer and use it in GitHub Desktop.
chef
# Add item to runlist
export item='recipe[job::redis]'
knife exec -E 'nodes.find("chef_environment:staging") {|n| puts n.run_list << ENV["item"] unless n.run_list.include?(ENV["item"]); n.save }'
# Delete item from runlist
export item='recipe[job::redis]'
knife exec -E 'nodes.transform("chef_environment:staging") {|n| puts n.run_list.remove(ENV["item"]); n.save }'
# Replace item in runlist
export item_from='recipe[base::nginx]'
export item_to='role[frontend]'
knife exec -E 'nodes.find("chef_environment:staging") {|n| next unless n.run_list.include?(ENV["item_from"]); list = n.run_list.map{|x| x == ENV["item_from"] ? ENV["item_to"] : x }; puts n.run_list(list); n.save}'
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment