What i'm trying to do is generating lots of similar directory trees. I woul like to set a dict which describes the pattern of the tree. Then i want ansible to generate multiple directory trees with different indexes, generated from the special list.
Assume this simple playbook:
- hosts: [localhost]
vars:
instances: [1,2,3,4]
dirs:
- path: "/srvs/hosting{{ instance }}/dir1"
- path: "/srvs/hosting{{ instance }}/dir2"
# and so on ......
tasks:
- debug:
msg: "{{ item[1].path }}"
loop: "{{ instances | product(dirs) | list }}"
vars:
instance: "{{ item[0] }}"
When using {{ instance }} var inside the 'path' var i'm getting an error:
fatal: [localhost]: FAILED! => {"msg": "[{'path': '/srvs/hosting{{ instance }}/dir1'}, {'path': '/srvs/hosting{{ instance }}/dir2'}]: {{ item[0] }}: 'item' is undefined"}
What i 'm expecting to get:
ok: [localhost] => (item=[1, {'path': '/srvs/hosting1/dir1'}]) => {
"msg": {
"path": "/srvs/hosting1/dir1"
}
}
ok: [localhost] => (item=[1, {'path': '/srvs/hosting1/dir2'}]) => {
"msg": {
"path": "/srvs/hosting1/dir2"
}
}
ok: [localhost] => (item=[2, {'path': '/srvs/hosting2/dir1'}]) => {
"msg": {
"path": "/srvs/hosting2/dir1"
}
}
ok: [localhost] => (item=[2, {'path': '/srvs/hosting2/dir2'}]) => {
"msg": {
"path": "/srvs/hosting2/dir2"
}
}
ok: [localhost] => (item=[3, {'path': '/srvs/hosting3/dir1'}]) => {
"msg": {
"path": "/srvs/hosting3/dir1"
}
}
ok: [localhost] => (item=[3, {'path': '/srvs/hosting3/dir2'}]) => {
"msg": {
"path": "/srvs/hosting3/dir2"
}
}
ok: [localhost] => (item=[4, {'path': '/srvs/hosting4/dir1'}]) => {
"msg": {
"path": "/srvs/hosting4/dir1"
}
}
ok: [localhost] => (item=[4, {'path': '/srvs/hosting4/dir2'}]) => {
"msg": {
"path": "/srvs/hosting4/dir2"
}
}
What am i missing?