I am using include_vars
to load variables from several .yaml
files
- hosts: localhost
vars:
files: "{{ query('varnames', 'files_[0-9]+')|
map('extract', hostvars.localhost, 'files')|
flatten }}"
tasks:
- find:
paths: "{{ playbook_dir }}"
recurse: true
patterns: test.yaml
register: files_from_dirs
- include_vars:
file: "{{ item }}"
name: "{{ name }}"
loop: "{{ files_from_dirs.files|map(attribute='path')|list }}"
loop_control:
extended: true
vars:
name: "files_{{ ansible_loop.index }}"
- debug:
var: files
while this works in ansible
when I run it in zuul
it doesn't work.
Either zuul
protects hostvars
for security reasons or it loads the vars in another namespace
is there a way to use another variable with include_vars
instead of hostvars
so I can have a reliable name handler to load the variables
for example something akin to (the code below doesn't work but I am trying to explain the concept)
- local_vars: {
'name': 'This acts like a pointer',
}
files: "{{ query('varnames', 'files_[0-9]+')|
map('extract', local_vars, 'files')|
flatten }}"
and to load into that dictionary as keys, or another method where I can have a local var to point to those dictionaries without using hostvar
- include_vars:
file: "{{ item }}"
name: "{{ name }}"
loop: "{{ files_from_dirs.files|map(attribute='path')|list }}"
loop_control:
extended: true
vars:
name: "local_vars.folders_{{ ansible_loop.index }}"