ruby 一个ruby脚本,用于创建一大堆厨师节点。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 一个ruby脚本,用于创建一大堆厨师节点。相关的知识,希望对你有一定的参考价值。

#!/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

以上是关于ruby 一个ruby脚本,用于创建一大堆厨师节点。的主要内容,如果未能解决你的问题,请参考以下文章

ruby 厨师中级班的处理程序

ruby 厨师中级班的处理程序食谱

ruby 厨师中级班的Ohai模块重构

厨师库或定义?

ruby 用于检查Codeship状态的简单Ruby脚本

Ruby / Rails - 更改时间的时区,而不更改值