Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Chef infra 如何在厨师食谱中动态查找主机的IP_Chef Infra - Fatal编程技术网

Chef infra 如何在厨师食谱中动态查找主机的IP

Chef infra 如何在厨师食谱中动态查找主机的IP,chef-infra,Chef Infra,我需要找到一个节点的IP,如果有的话。问题是“cluster_nodes.first”可以,但它没有任何方法,“.ip”不存在,cluster_nodes.first[:ip]也不存在,我在Chef Wiki上找不到任何信息 cluster_nodes = search(:node, "name:cluster1*") if cluster_nodes.size > 0 node[:primary_node] = cluster_nodes.first.ip else node[

我需要找到一个节点的IP,如果有的话。问题是“cluster_nodes.first”可以,但它没有任何方法,“.ip”不存在,cluster_nodes.first[:ip]也不存在,我在Chef Wiki上找不到任何信息

cluster_nodes = search(:node, "name:cluster1*")

if cluster_nodes.size > 0
  node[:primary_node] = cluster_nodes.first.ip
else
  node[:primary_node] = ''
end
错误:

[Sat, 01 Sep 2012 10:29:22 +0000] ERROR: Running exception handlers
[Sat, 01 Sep 2012 10:29:22 +0000] FATAL: Saving node information to /var/chef/cache/failed-run-data.json
[Sat, 01 Sep 2012 10:29:22 +0000] ERROR: Exception handlers complete
[Sat, 01 Sep 2012 10:29:22 +0000] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[Sat, 01 Sep 2012 10:29:22 +0000] FATAL: ArgumentError: Attribute ip is not defined!

haproxy配方它有一个很好的例子,这是一个取自该配方的片段:

cluster_nodes = search(:node, "name:cluster1*")
member = cluster_nodes.first if cluster_nodes

if cluster_nodes && cluster_nodes.size > 0
  primary_node = begin
    if member.attribute?('cloud')
      if node.attribute?('cloud') && (member['cloud']['provider'] == node['cloud']['provider'])
         member['cloud']['local_ipv4']
      else
        member['cloud']['public_ipv4']
      end
    else
      member['ipaddress']
    end
  end
else
  primary_node = ''
end
它对我有用。第一个节点获取一个空值,第二个、第三个等节点获取IP地址