我正在努力启动节点集群。在myrepo/cookbooks/mycookbook/.kitchen.yml
我有
driver:
name: vagrant
provisioner:
name: chef_zero
roles_path: '../../roles'
environments_path: '../../environments'
data_bags_path: '../../data_bags'
platforms:
- name: ubuntu-12.04
suites:
- name: node01
driver:
vm_hostname: "node01.localhost"
run_list:
- role[genericnode]
provisioner:
client_rb:
environment: development
在myrepo/cookbooks/mycookbook/recipes/default.rb
我有
nodes = []
search(:node, 'role:genericnode').each do |node|
nodes.push("http://#{node['ipaddress']}:8080")
end
node.default['mysetting'] = nodes.join(',')
但是,在我的开发环境中,搜索返回一个空列表。我是否需要上述.kitchen.yml
设置才能使用角色genericnode
访问网络中节点的 IP 地址?
附加信息:
角色如下:
{
"name": "genericnode",
"description": "Generic Node",
"json_class": "Chef::Role",
"default_attributes": {
},
"override_attributes": {
},
"chef_type": "role",
"run_list": [
"recipe[apt::default]", "recipe[mycookbook::default]"
],
"env_run_lists": {
}
}
要在chef_zero下进行搜索,您需要提供节点对象的文件夹作为 JSON 作为搜索的数据。搜索不会找到当前节点,除非它在服务器上(除非将其添加到该节点/文件夹,否则不会。
通常的解决方法是同时使用搜索和检查本地值。
ips = []
search(:node, 'roles:genericnode').each do |n|
ips << n['ipaddress']
end
if node['roles'].include?'(genericnode')
ips |= [node['ipaddress']]
end
node.default['mysetting'] = ips.map{|ip| "http://#{ip}:8080"}.join(',')