---
|
- hosts: localhost
|
connection: local
|
gather_facts: no
|
tags: include_vars
|
tasks:
|
- name: Stat default variables files (both yaml/yml extensions)
|
vars:
|
find_me:
|
# Global default vars related to the cloud provider
|
- cloud_providers/{{ cloud_provider }}_default_vars
|
# Legacy env_vars.yml (replaced by default_vars.yml)
|
- configs/{{ env_type }}/env_vars
|
# Default vars of the config
|
- configs/{{ env_type }}/default_vars
|
# Default vars of the config, specific to a cloud provider
|
- configs/{{ env_type }}/default_vars.{{ cloud_provider }}
|
- configs/{{ env_type }}/default_vars_{{ cloud_provider }}
|
# Lecacy secret vars file.
|
- configs/{{ env_type }}/env_secret_vars
|
extensions:
|
- yaml
|
- yml
|
stat:
|
path: "{{ item[0] ~ '.' ~ item[1] }}"
|
loop: "{{ find_me | product(extensions) | list }}"
|
register: rstat_varfiles
|
|
- name: Stat variables files
|
vars:
|
find_me:
|
# secret file path passed as extra-var
|
- "{{ secret_file | d('/secret/file/not/passed') }}"
|
stat:
|
path: "{{ item }}"
|
loop: "{{ find_me }}"
|
register: rstat2_varfiles
|
|
|
- hosts:
|
- localhost
|
- all
|
connection: local
|
gather_facts: no
|
tags: include_vars
|
tasks:
|
- name: Set output_dir for all hosts
|
set_fact:
|
output_dir: "{{ hostvars.localhost.output_dir }}"
|
when: hostvars.localhost.output_dir is defined
|
|
- name: Include variables files
|
include_vars:
|
file: "{{ item.stat.path }}"
|
when:
|
- item is not skipped
|
- item.stat.exists
|
loop: "{{ hostvars.localhost.rstat_varfiles.results + hostvars.localhost.rstat2_varfiles.results }}"
|
loop_control:
|
label: >-
|
{{ (
|
item.stat.path
|
| default('skipped')
|
) if 'stat' in item else item }}
|