Ansible - 为相同的优先级附加变量

时间:2016-11-09 08:45:11

标签: append ansible operator-precedence

我想将set_fact的变量附加到相同的优先级中。请看这个链接:http://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable

两个yml文件中变量的命名必须相同。

group_vars/all.yml我定义了:

my_var: 
  - value
  - another

group_vars/hostgroup.yml我定义了

my_var: 
  - win

我期望的my_var是:

{{ value }}{{ another }}{{ win }}

实际上是什么:

{{ win }}

如何确保我的set_fact附加两个变量。

1 个答案:

答案 0 :(得分:1)

无法将列表与默认库存插件合并。

您唯一的选择是在运行时将它们与set_fact合并:

- set_fact:
    my_var: "{{ my_var + ['win'] }}"