node search is giving nothing in test kitchen

2019-03-06 10:34发布

No output from search in test kitchen

Throwing error check the recipe and suggest me some details

Node JSON file

{
    "id": "cldb",
    "chef_type": "node",
    "json_class": "Chef::Node",
    "run_list": [],
    "automatic": {
        "hostname": "cldb.net",
        "fqdn":"127.0.0.1",
        "name": "cldb.net",
        "ipaddress": "127.0.0.1",
        "roles": [],
        "cldb" : true
    }
}

Recipe


cldbNodes = search(:node, "cldb:true")

cldb = "#{cldbNodes["fqdn"]}"

file '/tmp/test.txt' do
    content "#{cldb}"
end

1条回答
冷血范
2楼-- · 2019-03-06 11:00

To summarize from the comments above, search(...) returns an array so you need to get a specific element, usually the first, before you can access node data.

Using the example above, it would be something like:

cldbNodes = search(:node, "cldb:true")

cldb = cldbNodes.first["fqdn"]

file '/tmp/test.txt' do
    content cldb
end
查看更多
登录 后发表回答