【问题标题】:How to search the .kitchen.yml attributes如何搜索 .kitchen.yml 属性
【发布时间】:2017-03-15 14:52:31
【问题描述】:

我想搜索主机名

searchnode = search(:node, "zookeeper:true")

想要将输出 Hostname.fqdn.com 作为节点,但我没有得到它。也许我不知道如何访问该属性。

---
driver:
  name: vagrant

provisioner:
  name: chef_zero
  environments_path: test/integration/default/environments
  client_rb:
    environment: stg

  always_update_cookbooks: true

verifier:
  name: inspec

platforms:
  - name: centos-7.2

suites:
  - name: Hostname.fqdn.com
    run_list:

          - recipe[test-cookbook::test]


    data_bags_path: "test/integration/default/data_bags"


attributes: {zookeeper: "true"}

【问题讨论】:

  • 您明确地想要搜索,对吧?我假设你知道如何访问当前node 的属性..
  • 不,我不知道通过测试厨房的当前节点属性
  • node['zookeeper'] 对您来说真的很陌生吗?请阅读learn.chef.io上的教程。
  • 不确定,如果我得到你的真正问题。
  • 不,你得到的答案是缩进错误

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


【解决方案1】:

您的.kitchen.yml 无效,因为顶级attributes 部分被忽略。你应该把它移到suite的元素下面(缩进对YAML很重要!):

suites:
  - name: Hostname.fqdn.com
    run_list:
      - recipe[test-cookbook::test]
    data_bags_path: "test/integration/default/data_bags"
    attributes: {zookeeper: "true"}

然后,您的search 应该会找到该节点。您可以使用kitchen diagnose 查看生成的属性。

如果要模拟测试厨房中的其他节点,可以将包含节点定义的 JSON 文件放在 test/integration/nodes 中(如 this cookbook 中使用的那样;可以通过 node_path 配置)。然后,您可以使用搜索根据其属性或运行列表“发现”其他节点。

【讨论】:

  • 复制时我复制了 run_list: - recipe[test-cookbook::test]
  • 非常感谢是的(缩进对 YAML 很重要!)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-17
  • 1970-01-01
  • 1970-01-01
  • 2013-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多