Kitchen:给一个节点添加一个角色

Kitchen: add a role to a node

我们的一个应用程序使用 gunicorn 并通过厨师食谱进行配置。

cookbook有一些属性,其中之一是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'
    }
  }
)

鉴于 roles 属性优先于 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 角色的一部分的事实...

感谢任何帮助。

最佳。

将你的角色放在test/integration目录下,它会被零号厨师自动拾取:

├── .kitchen.yml
└── test
    └── integration
        └── roles
            └── myrole.json

然后在厨房文件中创建两个测试套件,一个使用食谱食谱,另一个使用角色:

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

kitchen converge后,gunicorn 19.3.0 安装完毕。 谢谢!