1

我正在使用 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?

4

1 回答 1

0

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

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

于 2019-12-29T13:14:32.223 回答