servers.each do |s|
run_list_str = %[knife node show #{s} -r -f json]
run_list = JSON.parse(s_run_list)
if not run_list.include? “role[base]”
%x[knife node run_list add #{s} “role[base]”]
end
if not run_list.include? “role[int0]” or not run_list.include? "role[ext0]"
if s =~ /^ext.*/
%x[knife node run_list add #{s} "role[ext0]"]
else
%x[knife node run_list add #{s} "role[int0]"]
end
end
if not run_list.include? "role[econ]"
%x[knife node run_list add #{s} "role[econ]"]
end
%x[ knife ssh name:{s} “chef-client” -x root -i .chef/identity ]
end
Here's part of the code I use to launch knife bootstrap programatically.
It's a mix of several parts so it won't work as is, but you can figure out
the variables:
servers.each do |s|
run_list_str = %[knife node show #{s} -r -f json]
run_list = JSON.parse(s_run_list)
if not run_list.include? "role[base]"
%x[knife node run_list add #{s} "role[base]"]
end
if not run_list.include? "role[int0]" or not run_list.include? "role[ext0]"
if s =~ /^ext.*$/
%x[knife node run_list add #{s} "role[ext0]"]
else
%x[knife node run_list add #{s} "role[int0]"]
end
end
if not run_list.include? "role[econ]"
%x[knife node run_list add #{s} "role[econ]"]
end
%x[ knife ssh name:${s} "chef-client" -x root -i .chef/identity ]
end
Instead of shelling out to knife each time, could I just require 'Chef',
initialize a few values, and work from there?
You could use Chef as a library. Some people use knife as a library,
which is discouraged because it is a client that uses the chef library
itself, but I understand why.
For something simple like this, you should use 'knife exec'
Here's part of the code I use to launch knife bootstrap programatically.
It's a mix of several parts so it won't work as is, but you can figure out
the variables:
Thanks btm, I was.aware of knife exec but didn't know that it had access to
all of chefs API and the node object
On Nov 23, 2011 6:24 PM, "Bryan McLellan" btm@loftninjas.org wrote:
Instead of shelling out to knife each time, could I just require 'Chef',
initialize a few values, and work from there?
You could use Chef as a library. Some people use knife as a library,
which is discouraged because it is a client that uses the chef library
itself, but I understand why.
For something simple like this, you should use 'knife exec'