【问题标题】:node search is giving nothing in test kitchen节点搜索在测试厨房中什么也没有
【发布时间】:2017-07-21 11:14:21
【问题描述】:

在测试厨房中搜索没有输出

投掷错误检查配方并建议我一些细节

节点 JSON 文件

{
    "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
    }
}

食谱


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

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

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

【问题讨论】:

  • 你的 kitchen.yml 配置是如何设置的,节点 JSON 文件的路径是什么?
  • --- 驱动程序:名称:vagrant 供应商:名称:chef_zero #nodes_path:测试/集成/节点环境_路径:测试/集成/默认/环境 client_rb:环境:测试 always_update_cookbooks:true 验证器:名称:检查平台:-名称:centos-7.2 套件:-名称:nodesearch run_list:-配方[nodesearch-cookbook::nodesearch_mapr]
  • driver: name: vagrant provisioner: name: chef_zero environments_path: test/integration/default/environments client_rb: environment: test verifier: name: inspec platforms: - name: centos-7.2 suites: - name: nodesearch run_list: - recipe[nodesearch-cookbook::nodesearch_mapr]
  • nodes_path: 测试/集成/节点
  • 好的,JSON 文件的完整路径是什么?

标签: chef-infra chef-recipe test-kitchen


【解决方案1】:

从上面的 cmets 总结,search(...) 返回一个数组,因此您需要获取特定元素,通常是第一个,然后才能访问节点数据。

使用上面的例子,它会是这样的:

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

cldb = cldbNodes.first["fqdn"]

file '/tmp/test.txt' do
    content cldb
end

【讨论】:

  • cldbNodes = search(:node, "node_color:green") cldbList = "" cldbNodes.each do |cldb| cldbList += cldb end cldb1 = cldbList[1]['hostname'] file '/tmp/test.txt' do content "#{cldb1}" end
  • 现在问题是 cldbList += cldb
  • 未定义方法 `[]' for nil:NilClass for
  • i = 0 cldbList = "" cldbNodes.each 做 |cldb| cldbList += cldb[i]['hostname'] i +=1 end
  • 我想将 cldbNodes['hostname'] 数组保存到单个变量中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多