Last active
October 24, 2016 10:35
-
-
Save odyssey4me/17c2da743454549f9be8dac03489de39 to your computer and use it in GitHub Desktop.
Ansible 2.1.1 experimentation with conditional include handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
apt-get update && \ | |
apt-get purge -y nano && \ | |
apt-get install -y git vim tmux fail2ban build-essential python2.7 python-dev libssl-dev libffi-dev | |
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python2.7 | |
pip install -U ansible==2.1.1 | |
ansible-playbook -i 01-inventory.ini 02-playbook.yml -vv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[all] | |
localhost1 ansible_connection=local | |
localhost2 ansible_connection=local | |
localhost3 ansible_connection=local | |
localhost4 ansible_connection=local | |
localhost5 ansible_connection=local | |
[group1] | |
localhost1 | |
localhost2 | |
localhost3 | |
localhost4 | |
localhost5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Test conditional include (using inventory/group) | |
hosts: group1 | |
gather_facts: false | |
tasks: | |
- include: 03-included-task.yml | |
static: no | |
when: inventory_hostname == groups['group1'][0] | |
vars: | |
include_me: "{{ inventory_hostname == groups['group1'][0] }}" | |
- name: Test conditional include (using vars) | |
hosts: group1 | |
gather_facts: false | |
tasks: | |
- include: 03-included-task.yml | |
static: no | |
when: include_me | bool | |
vars: | |
include_me: "{{ inventory_hostname == groups['group1'][0] }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- debug: | |
msg: "included-task -> include_me: {{ include_me }}" | |
when: include_me is defined | |
- debug: | |
msg: "included-task -> arbitrary message" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment