2016-12-16 5 views
0

で使用することはできません生成:シェフの検索がして、私は特定のノードのためのシェフの検索を使用しようとしているノード名は、レシピ

hosts = search(:node, 'chef_environment:STG AND role:elasticsearch') 
Chef::Log.warn("Hosts are #{hosts}") 
hosts.each do |node| 
    Chef::Log.warn("hostname is: #{node['name']} and has the following tags #{node["tags"]}") 
end 

最初Chef::Log.warnの結果は次のとおりです。

[2016-12-16T10:09:55+00:00] WARN: Hosts are [#<Chef::Node:0x00000002e0acc0 @chef_server_rest=nil, @name="tels01", @chef_environment="STG", @primary_runlist=#<Chef::RunList:0x00000002e0ac48 @run_list_items=[#<Chef::RunList::RunListItem:0x00000002df1568 @version=nil, @type=:role, @name="base">, #<Chef::RunList::RunListItem:0x00000002df0de8 @version=nil, @type=:role, @name="elasticsearch">]>, @override_runlist=#<Chef::RunList:0x00000002e0ab80 @run_list_items=[]>, @policy_name=nil, @policy_group=nil, @attributes=#<Chef::Node::Attribute @default={}, @env_default={}, @role_default={}, @force_default={}, @normal={"tags"=>["linux", "els"]}, @override={}, @role_override={}, @env_override={}, @force_override={}, @automatic={}, @merged_attributes=nil, @properties=nil>, @run_state={}>, ... 

そして、 Chef::Log.warn("hostname is: #{node['name']} and has the following tags #{node["tags"]}")の結果は、だから私はミリアンペアのホスト名を取得することはできません

[2016-12-16T10:09:55+00:00] WARN: hostname is: and has the following tags ["linux", "els"] 
[2016-12-16T10:09:55+00:00] WARN: hostname is: and has the following tags ["linux", "els"] 
[2016-12-16T10:09:55+00:00] WARN: hostname is: and has the following tags ["linux", "elasticsearch"] 
[2016-12-16T10:09:55+00:00] WARN: hostname is: and has the following tags ["linux", "elasticsearch"] 
[2016-12-16T10:09:55+00:00] WARN: hostname is: and has the following tags ["linux", "elasticsearch"] 

ですクエリはクエリに起因します。私も#{node['hostname']}で試しましたが、同じ結果でした

私は間違っていますか? ありがとうございます。

編集:

ありがとうございます。 els_hosts = search(:node, 'chef_environment:STG AND role:elasticsearch') Chef::Log.warn("Hosts are #{els_hosts}") els_hosts.each do |host| Chef::Log.warn("hostname is: #{host["fqdn"]} and has the following tags #{host["tags"]}") endを使用する結果は同じです。Compiling Cookbooks... [2016-12-16T12:47:18+00:00] WARN: Hosts are [#<Chef::Node:0x0000000542fbf8 @chef_server_rest=nil, @name="clj-lc-tels01", @chef_environment="LC", @primary_runlist=#<Chef::RunList:0x0000000542fb08 @run_list_items=[#<Chef::RunList::RunListItem:0x0000000542d1c8 @version=nil, @type=:role, @name="base">, #<Chef::RunList::RunListItem:0x0000000542cfe8 @version=nil, @type=:role, @name="lc_elasticsearch">]>, @override_runlist=#<Chef::RunList:0x0000000542fa18 @run_list_items=[]>, @policy_name=nil, @policy_group=nil, @attributes=#<Chef::Node::Attribute @default={}, @env_default={}, @role_default={}, @force_default={}, @normal={"tags"=>["linux", "test_els"]}, @override={}, @role_override={}, @env_override={}, @force_override={}, @automatic={}, @merged_attributes=nil, @properties=nil>, @run_state={}>, ... [2016-12-16T12:47:18+00:00] WARN: hostname is: and has the following tags ["linux", "test_els"] [2016-12-16T12:47:18+00:00] WARN: hostname is: and has the following tags ["linux", "test_els"] [2016-12-16T12:47:18+00:00] WARN: hostname is: and has the following tags ["linux", "elasticsearch"] [2016-12-16T12:47:18+00:00] WARN: hostname is: and has the following tags ["linux", "elasticsearch"] [2016-12-16T12:47:18+00:00] WARN: hostname is: and has the following tags ["linux", "elasticsearch"]

+0

まず、変数として 'node'を使用しないでください。それは通常あなた自身のノードオブジェクトを指しているので、あなたは狂ってしまいます。 – StephenKing

+0

'node'は、実際のノードを参照するために使用される特別な名前です。グローバルノードオブジェクトを使用して検索結果を混乱させるでしょう。 '| node |'を '| host |'で置き換え、あなたのログにアクセスしてアクセスしていることを確認してください。 – Tensibai

+0

第2に、IIRCの 'name'はクライアント名でなければなりません。これはホスト名とは関係ありませんが、空であってはいけません。 'host ['fqdn']'や 'host ['hostname']'の使用を検討してください。 – StephenKing

答えて

0

これはnode.nameです。名前は属性ではなく、実際の方法です。

0

問題は実際にはノード定義をダウンロードし、すべてのohai属性を取り除き、env属性、実行リスト、および名前のみを保持するという事実から来ています。だから私はその名前を手に入れられなかった。

ありがとうございました。 Gabriel

関連する問題