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?

Thanks,
Dave

You can do something like this:

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

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

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

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 n.save 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.

Dave

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

1 Like