Created
June 22, 2015 20:53
-
-
Save ctdk/16623c2453640448b6d6 to your computer and use it in GitHub Desktop.
A ruby script to create a whole bunch of chef nodes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'chef-api' | |
require 'fauxhai' | |
include ChefAPI::Resource | |
ChefAPI.configure do |config| | |
config.endpoint = 'http://HOSTNAME:4545' | |
config.client = 'admin' | |
config.key = '~/etc/goiardi/admin.pem' | |
end | |
datacenters = [ { :city => "Vagrantheim", :cluster => "VAG", :name => "VAG", :region => "US-West" }, { :city => "San Jose", :cluster => "SJC", :name => "SJC", :region => "US-California" }, { :city => "McMurdo", :cluster => "MCM", :name => "MCM", :region => "Antarctica" } ] | |
run_lists = [ "recipe[datacenter::vagrant]", "role[foo]", "recipe[scout],recipe[bnerk]", "role[foo],recipe[scout]" ] | |
pkeys = [ "debian", "ubuntu", "centos" ] | |
platforms = { | |
"debian" => [ | |
"6.0.5", "7.5", "7.8" | |
], | |
"ubuntu" => [ | |
"12.04", "14.04", "10.04" | |
], | |
"centos" => [ | |
"5.9", "6.6", "7.0" | |
] | |
} | |
(100..10000).each do |x| | |
p = rand(3) | |
v = rand(3) | |
auto = Fauxhai.mock(platform: pkeys[p], version: platforms[pkeys[p]][v]) do |node| | |
node['hostname'] = "server#{x}.example.com" | |
end | |
n = Node.new | |
n.name = "server#{x}.example.com" | |
n.automatic = auto.data | |
ds = rand(3) | |
rl = rand(4) | |
n.default['datacenter'] = datacenters[ds] | |
n.run_list = run_lists[rl].split(/,/) | |
n.save | |
Client.create(:name => n.name) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
without chef-api
note.. unless you need to populate the node in chef server, you wont need save and configure related code