Skip to content

Instantly share code, notes, and snippets.

@halberom
Created April 15, 2014 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halberom/10719583 to your computer and use it in GitHub Desktop.
Save halberom/10719583 to your computer and use it in GitHub Desktop.
load vars based on distribution
# vars/amazon.yml
---
foo: bar
TASK: [Group hosts by OS and version] *****************************************
changed: [localhost]
TASK: [debug var=groups] ******************************************************
ok: [localhost] => {
"groups": {
"Amazon-2014.03": [
"localhost"
],
"all": [
"localhost"
],
"ungrouped": [
"localhost"
]
}
}
PLAY [Amazon*] ****************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
localhost: importing /etc/ansible/vars/amazon.yml
TASK: [do something with vars] ************************************************
changed: [localhost]
TASK: [debug var=foo] *********************************************************
ok: [localhost] => {
"foo": "bar"
}
PLAY RECAP ********************************************************************
localhost : ok=6 changed=2 unreachable=0 failed=0
---
- hosts: all
tasks:
- name: Group hosts by OS and version
group_by: key={{ ansible_distribution }}-{{ ansible_distribution_version }}
- debug: var=groups
- hosts: Amazon*
vars_files:
- "vars/{{ ansible_distribution | lower }}.yml"
tasks:
- name: do something with vars
shell: echo {{ foo }}
- debug: var=foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment