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
Well, you cannot directly build an array, but you can achieve the same effort with a dict.
Suppose you want to construct an array:
[{
name: 'bob',
age: 30
}, {
name: 'alice',
age: 35
}]
You can put each element in a file like:
bob:
name: bob
age: 30
alice:
name: alice
age: 35
Place these files in the same dir (e.g. user), then use include_vars to load the whole dir:
- name: Include vars
include_vars:
name: users
dir: user
This will give you a dict users:
users:
alice:
name: alice
age: 35
bob:
name: bob
age: 30
User the dict2items filter in ansible, you get the array you want