Batch edit multiple nodes?

I need to edit the runlist of a bunch of nodes, changing the name of a role. I know how to do this using "knife node edit...", but I need to do this on 85 nodes. What are my options for scripting this change so I don't need to type "knife node edit" 85 times?


You can do something like this:

knife exec -E '"your_search_query_for_the_85_nodes").each { |n| n.run_list="New run list"; }

You may work with the run_list differently too to replace "in place":

knife exec -E '"search_query") { |n| n.run_list.reset!( { |r| r == "role[old_role]" ? "role[new_role]" : r } ); puts "New runlist for #{n}: #{n.run_list}"; }'

The idea is to loop over a search query, then reset each node run_list to the new version made by replacing the role.

You can remove the from the code above to just see what would be the result

Thanks! I'll give that a try. I've never done much with knife exec, but this looks like a good reason to start.


That works beautifully. I never would have come up with that. Thanks again!

1 Like