Skip to content

Instantly share code, notes, and snippets.

@mchubby
Created August 27, 2018 16:55
Show Gist options
  • Save mchubby/8dfb3f11a618a05674c3f7c91fd8fe67 to your computer and use it in GitHub Desktop.
Save mchubby/8dfb3f11a618a05674c3f7c91fd8fe67 to your computer and use it in GitHub Desktop.
Have host_vars or group_vars greater precedence than include_vars counterparts.
---
- name: Include vars based on various criteria, into platformspec hash.
include_vars:
file: "{{ item }}"
name: platformspec
with_first_found:
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
# inspired by https://www.samdarwin.com/ansible-default-vars/
- name: Set facts while having include_vars variables have lower precedence
set_fact:
"{{ item.key }}": "{{ item.value|default(vars[item.key]) }}"
with_dict: "{{ platformspec }}"
- name: debug
debug: var=vars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment