Skip to content

Instantly share code, notes, and snippets.

@odyssey4me
Created November 20, 2017 14:25
Show Gist options
  • Save odyssey4me/7673d9bf4321079e43d682e5d011a40f to your computer and use it in GitHub Desktop.
Save odyssey4me/7673d9bf4321079e43d682e5d011a40f to your computer and use it in GitHub Desktop.
Show difference between static and dynamic include execution
---
- name: Test conditional include (static)
hosts: localhost
connection: local
gather_facts: false
tasks:
- include: 01-included-tasks.yml
when: include_me | bool
- name: Test conditional include (dynamic)
hosts: localhost
connection: local
gather_facts: false
tasks:
- include: 01-included-tasks.yml
static: no
when: include_me | bool
---
- debug:
msg: "included-task -> include_me: {{ include_me }}"
- debug:
msg: "included-task -> arbitrary message"
(ansible-2.3):~/venvs/ansible-2.3$ ansible-playbook 00-test-playbook.yml -e include_me=no
PLAY [Test conditional include (static)] ***********************************************************************************************************************
TASK [debug] ***************************************************************************************************************************************************
skipping: [localhost]
TASK [debug] ***************************************************************************************************************************************************
skipping: [localhost]
PLAY [Test conditional include (dynamic)] **********************************************************************************************************************
TASK [include] *************************************************************************************************************************************************
skipping: [localhost]
PLAY RECAP *****************************************************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=0
(ansible-2.3):~/venvs/ansible-2.3$ ansible-playbook 00-test-playbook.yml -e include_me=yes
PLAY [Test conditional include (static)] ***********************************************************************************************************************
TASK [debug] ***************************************************************************************************************************************************
ok: [localhost] => {
"msg": "included-task -> include_me: yes"
}
TASK [debug] ***************************************************************************************************************************************************
ok: [localhost] => {
"msg": "included-task -> arbitrary message"
}
PLAY [Test conditional include (dynamic)] **********************************************************************************************************************
TASK [include] *************************************************************************************************************************************************
included: /Users/jess8308/venvs/ansible-2.3/01-included-tasks.yml for localhost
TASK [debug] ***************************************************************************************************************************************************
ok: [localhost] => {
"msg": "included-task -> include_me: yes"
}
TASK [debug] ***************************************************************************************************************************************************
ok: [localhost] => {
"msg": "included-task -> arbitrary message"
}
PLAY RECAP *****************************************************************************************************************************************************
localhost : ok=5 changed=0 unreachable=0 failed=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment