Search code examples
appendansibleoperator-precedence

Ansible - Append variable for same precedence


I'd like to append my variable for a set_fact in the same precedence. See this link: http://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable

The naming of the variable has to be the same in both yml files.

In group_vars/all.yml I have defined:

my_var: 
  - value
  - another

And in group_vars/hostgroup.yml I have defined

my_var: 
  - win

What I expect my_var is:

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

What it actually is:

{{ win }}

How do I ensure my set_fact appends both variables.


Solution

  • There is no way to merge lists with default inventory plugins.

    Your only option is to merge them in runtime with set_fact:

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