In Ansible, how to combine variables from separate files into one array?

后端 未结 7 760
执笔经年
执笔经年 2020-12-03 21:27

In Ansible, in a role, I have vars files like this:

vars/
    app1.yml
    app2.yml

Each file contains vars specific to an app/website like

7条回答
  •  一个人的身影
    2020-12-03 21:40

    Wanted to post a possible alternate solution by getting a list of variables that match a pattern, then you can just process all those variables, sorta manual merge.

    The following code block gives an example of pulling all variables that match a specific pattern and looping. you could set a new fact with them merged, or simply process them all individually.

    - name: "debug2"   debug:
        msg: "value is: {{ lookup('vars', item) }} "   
      loop: "{{ hostvars[inventory_hostname] | select('match', '^linux_hosts_entries') |list  }}"
    

    see the following post for further details.

提交回复
热议问题