简体   繁体   English

我如何通过厨师预配置获得预配置计算机的ipaddress

[英]How do I get the ipaddress of a provisioned machine via chef provisioning

I am writing a chef provisioning recipe to provision a cluster of machines. 我正在写一个厨师调配配方来调配一台机器。 I have more/less done that, but now I want to set the hosts file of all of the provisioned machines to be the dynamically assigned IP addresses of all of the other hosts. 我做了更多/更少的事情,但是现在我想将所有配置的机器的hosts文件设置为所有其他主机的动态分配的IP地址。 Is there a way to query what the ip address of a provisioned host is? 有没有办法查询已配置主机的IP地址是什么?

Not on ChefProvisioning layer, but I have done this as follows: 不在ChefProvisioning层上,但是我这样做如下:

You can use hostsfile cookbook from chef supermarket and a databag in chef server. 您可以使用厨师超市的hostsfile食谱和厨师服务器中的数据

It is possible to access to one node IP with attribute node[:ipaddress] , store it inside the databag and then access with a loop through all ips, using hostsfile cookbook to create/update entries with resource hostsfile_entry , something similar to: 可以使用属性node[:ipaddress]访问一个节点IP,将其存储在数据袋中,然后通过所有ip循环访问,使用hostsfile cookbook使用资源hostsfile_entry创建/更新条目,类似于:

node[:list_of_hosts].each do |name, ip|
  hostsfile_entry ip do
    hostname name
    action [:create_if_missing, :update]
  end
end

Assuming there that you have in a hash the list of IPs and hostnames from the databag. 假设您在哈希表中包含了数据包中的IP和主机名列表。

Hope you found this helpful. 希望对您有所帮助。

The short answer is: you don't which is one reason you shouldn't be using chef-provisioning. 简短的答案是:您不这样做,这是您不应该使用厨师调配的原因之一。 Long answer, some of the drivers allow accessing the underlying object through the resource but what you'll end up with looks nothing like normal Chef code. 长话大说,某些驱动程序允许通过资源访问基础对象,但最终结果看起来不像普通的Chef代码。 Store each machine object in an array and then later you can try to use that for a second pass on things. 将每个machine对象存储在一个数组中,然后您可以尝试将其用于第二次传递。

The real answer is that the provisioning layer shouldn't be doing this, use something like Chef Search or the relevant cloud API from the recipe on the actual provisioned nodes like you would with "normal" Chef. 真正的答案是,配置层不应该这样做,而是像在使用“普通” Chef一样,在实际的已配置节点上使用Chef Search或配方中的相关云API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM