Jim Rigsbee
2020-02-12 2f15941d40fc11d9042d0658ec2086a85a150a61
commit | author | age
192691 1 ---
051a61 2 - hosts: localhost
192691 3   connection: local
GC 4   gather_facts: no
ba0c61 5   tags: include_vars
192691 6   tasks:
bae3d3 7     - name: Stat default variables files (both yaml/yml extensions)
GC 8       vars:
9         find_me:
10           # Global default vars related to the cloud provider
11           - cloud_providers/{{ cloud_provider }}_default_vars
12           # Legacy env_vars.yml (replaced by default_vars.yml)
13           - configs/{{ env_type }}/env_vars
14           # Default vars of the config
15           - configs/{{ env_type }}/default_vars
16           # Default vars of the config, specific to a cloud provider
17           - configs/{{ env_type }}/default_vars.{{ cloud_provider }}
18           - configs/{{ env_type }}/default_vars_{{ cloud_provider }}
19           # Lecacy secret vars file.
20           - configs/{{ env_type }}/env_secret_vars
21         extensions:
22           - yaml
23           - yml
192691 24       stat:
bae3d3 25         path: "{{ item[0] ~ '.' ~ item[1] }}"
GC 26       loop: "{{ find_me | product(extensions) | list }}"
192691 27       register: rstat_varfiles
GC 28
bae3d3 29     - name: Stat variables files
GC 30       vars:
31         find_me:
32           # secret file path passed as extra-var
33           - "{{ secret_file | d('/secret/file/not/passed') }}"
34       stat:
35         path: "{{ item }}"
36       loop: "{{ find_me }}"
37       register: rstat2_varfiles
38
051a61 39
GC 40 - hosts:
41     - localhost
42     - all
43   connection: local
44   gather_facts: no
45   tags: include_vars
46   tasks:
47     - name: Set output_dir for all hosts
2f1594 48       delegate_to: localhost
051a61 49       set_fact:
GC 50         output_dir: "{{ hostvars.localhost.output_dir }}"
51       when: hostvars.localhost.output_dir is defined
52
bae3d3 53     - name: Include variables files
2f1594 54       delegate_to: localhost
192691 55       include_vars:
GC 56         file: "{{ item.stat.path }}"
dafba2 57       when:
GC 58         - item is not skipped
59         - item.stat.exists
051a61 60       loop: "{{ hostvars.localhost.rstat_varfiles.results + hostvars.localhost.rstat2_varfiles.results }}"
192691 61       loop_control:
dafba2 62         label: >-
GC 63           {{ (
64             item.stat.path
0e7260 65             | default('skipped')
dafba2 66           ) if 'stat' in item else item }}