group_vars/siteA.yml
---
site_name: appA
port: 8080
group_vars/siteB.yml
---
site_name: appB
port: 8090
- name: print out the value of site_name and port for each of the group_vars files
debug: msg="My site {{ site_name }} is on port {{ port }}"
---
- name: include_vars example
hosts: all
tasks:
- name: Debug hostname.
debug:
var: inventory_hostname
# Different filenames with the same variables *should* override the variables for each instance of playbook execution.
# But precedence is tricky and I've had trouble getting things like this to work in the past, so ymmv.
- name: Include variables based on hostname.
include_vars: "vars/{{ inventory_hostname }}.yml"
- name: Print site name and port number.
debug:
msg: "My site {{ site_name }} is running on port {{ port_number }}."
...
# vim: ft=ansible:
for( one_filename in fileglob( vars/*.yml) {
- include_vars "{{ one_filename ))"
- debug: msg="{{ site_name }} on port {{ port }}"
}
- include_vars "{{ item }}"
with_fileglob:
- "vars/*.yml"