node search is giving nothing in test kitchen

2019-03-06 10:24发布

问题:

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:

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