【问题标题】:Re-using existing ansible group_vars with molecule重新使用现有的 ansible group_vars 和分子
【发布时间】:2019-12-28 23:05:31
【问题描述】:

我正在使用 Molecule 为我所有现有的 Ansible 角色添加测试。 我现有的 Ansible 剧本使用如下变量级别:

file: playbook_dir/group_vars/all
contents: global variables, applicable to all everything (hosts, inventories etc.)

file: playbook_dir/inventories/<inventory>/group_vars/all
contents: variables applicable to all hosts in this inventory.

file: playbook_dir/inventories/<inventory>/group_vars/<group>
contents: variables applicable only to this group.

在为我现有的角色设置 Molecule 时,我至少需要访问“全局变量”(我列表中的第一个),我设法通过添加链接来实现这一点,如下所示:

provisioner:
  name: ansible
  inventory:
    links:
      group_vars: ../../../../group_vars # These are the 'global' group_vars as described above.

到目前为止一切都很好,对。但是,有几个角色需要设置不属于“全局”组变量的变量;即库存特定的。 我发现:

  1. 这些链接只允许建立一个链接,因此链接到多个 group_vars 似乎不是一种选择。
  2. inventory.links.group_vars 和inventory.group_vars 是互斥的。

我的问题:如何重复使用现有的“全局变量”,以及 a) 使用现有库存特定 group_vars,或 b) 定义库存特定 group_vars?

【问题讨论】:

    标签: molecule


    【解决方案1】:

    您可以直接在molecule.yml 中定义特定于您的分子测试的库存group_vars。这也适用于host_vars

    参考:https://molecule.readthedocs.io/en/stable/configuration.html#id22(在页面上搜索“库存:”)。

    【讨论】:

    • 是的,但是当您这样做时,您将无法再链接到现有的 vars 文件。我的问题是是否有办法做到这两点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-01
    • 2021-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多