node search is giving nothing in test kitchen

霸气de小男生 提交于 2019-12-02 18:42:47

问题


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


来源:https://stackoverflow.com/questions/42543383/node-search-is-giving-nothing-in-test-kitchen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!