【问题标题】:Kitchen: add a role to a nodeKitchen:为节点添加角色
【发布时间】:2015-11-21 04:33:06
【问题描述】:

我们的一个应用使用 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'
    }
  }
)

鉴于角色属性优先于说明书属性,这应该有效。对吧??

现在我想用厨房来测试一下。在我们的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-infra test-kitchen


    【解决方案1】:

    把你的角色放在 test/integration 目录下,它会被 chef-zero 自动拾取:

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

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

    suites:
      - name: default
        run_list:
          - recipe[mycookbook::default]
      - name: withrole
        run_list:
          - role[myrole]
    

    使用角色管理tomcat属性的示例:

    【讨论】:

      【解决方案2】:

      谢谢你,马克,这是正确的:

      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。 谢谢!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-07-29
        • 2020-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-27
        • 2021-12-13
        • 1970-01-01
        相关资源
        最近更新 更多