Chef infra 厨房:将角色添加到节点

Chef infra 厨房:将角色添加到节点,chef-infra,test-kitchen,Chef Infra,Test Kitchen,我们的一个应用程序使用gunicorn,并通过厨师烹饪手册进行配置 烹饪书有一些属性,其中之一是gunicorn版本: grep 'version' attributes/default.rb default['myapp']['gunicorn']['version'] = '19.1.1' 仅当节点是特定角色的一部分时,我才想使用版本19.3.0。我创建了一个角色并为其赋予了一个属性: cat ../../roles/gunicorn-19.3.0.rb name 'gunicorn-19

我们的一个应用程序使用gunicorn,并通过厨师烹饪手册进行配置

烹饪书有一些属性,其中之一是gunicorn版本:

grep 'version' attributes/default.rb
default['myapp']['gunicorn']['version'] = '19.1.1'
仅当节点是特定角色的一部分时,我才想使用版本
19.3.0
。我创建了一个角色并为其赋予了一个属性:

cat ../../roles/gunicorn-19.3.0.rb
name 'gunicorn-19.3.0'

default_attributes(
  'mcnulty' => {
    'gunicorn' => {
      'version' => '19.3.0'
    }
  }
)
鉴于角色属性优先于cookbook属性,这应该是可行的。对吧

现在我想用厨房来测试一下。在我们的
kichen.yml
中,我们已经有了一个
default
套件,我复制并创建了一个
gunicorn-19.3.0
套件:

- name: gunicorn-19.3.0
    roles_path: '../../roles'
    run_list:
      - recipe[apt]
      - recipe[build-essential]
      - recipe[myapp]
    attributes: &attributes
      myapp:
        gunicorn:
          query:
            timeout: 5
            workers: 2
            sockdir: /var/run/myapp
          web:
            timeout: 5
            workers: 2
            sockdir: /var/run/myapp
现在我不知道如何模仿这个主机是
gunicorn-19.3.0
角色的一部分这一事实

感谢您的帮助


最佳。

将您的角色放在测试/集成目录下,chef zero将自动选择该角色:

├── .kitchen.yml
└── test
    └── integration
        └── roles
            └── myrole.json
然后在厨房文件中创建两个测试套件,一个使用cookbook recipe,另一个使用角色:

suites:
  - name: default
    run_list:
      - recipe[mycookbook::default]
  - name: withrole
    run_list:
      - role[myrole]
使用角色管理tomcat属性的示例:


    • 谢谢你,马克,这是一个很好的例子:

      cat test/integration/roles/gunicorn-19-3-0.json
      {
        "name": "gunicorn-19-3-0",
        "override_attributes": {
          "myapp": {
            "gunicorn": {
              "version": "19.3.0"
            }
          }
        }
      }
      
      cat .kitchen.yml
       - name: gunicorn-19.3.0
          #roles_path: '../../roles'
          run_list:
            - recipe[apt]
            - recipe[build-essential]
            - recipe[python]
            - recipe[myapp::default]
            - role[gunicorn-19-3-0]
          attributes: &attributes
            myapp:
              gunicorn:
                query:
                  timeout: 5
                  workers: 2
                  sockdir: /var/run/myapp
                web:
                  timeout: 5
                  workers: 2
                  sockdir: /var/run/myapp
      
      安装
      后,安装gunicorn 19.3.0。
      谢谢