Skip to content

Instantly share code, notes, and snippets.

@ssbarnea
Last active August 9, 2018 09:51
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 ssbarnea/0154a7b709d0cc378b012f40481afa61 to your computer and use it in GitHub Desktop.
Save ssbarnea/0154a7b709d0cc378b012f40481afa61 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ansible-playbook -i hosts
---
- hosts: all
gather_facts: no
tasks:
- name: values without gather_facts
debug:
msg: |
ansible_host = {{ ansible_host }}
ansible_hostname = {{ ansible_hostname | default('*undefined*') }}
inventory_hostname = {{ inventory_hostname | default('*undefined*') }}
- name: "values without gather_facts and with delegate_to: localhost"
debug:
msg: |
ansible_host = {{ ansible_host }}
ansible_hostname = {{ ansible_hostname | default('*undefined*') }}
inventory_hostname = {{ inventory_hostname | default('*undefined*') }}
delegate_to: localhost
- hosts: localhost
gather_facts: no
tasks:
- name: looping example run on localhost
debug:
msg: |
ansible_host = {{ ansible_host }}
ansible_hostname = {{ ansible_hostname | default('*undefined*') }}
inventory_hostname = {{ inventory_hostname | default('*undefined*') }}
hostvars['{{ item }}']['ansible_hostname'] = {{ hostvars[item]['ansible_hostname'] | default('*undefined*') }}
hostvars['{{ item }}']['ansible_host'] = {{ hostvars[item]['ansible_host'] | default('*undefined*') }}
hostvars['{{ item }}']['inventory_hostname'] = {{ hostvars[item]['inventory_hostname'] | default('*undefined*') }}
with_items: "{{ groups['all'] }}"
PLAY [all] *************************************************************************************************************
TASK [values without gather_facts] *************************************************************************************
Thursday 09 August 2018 10:51:20 +0100 (0:00:00.055) 0:00:00.055 *******
ok: [undercloud] => {}

MSG:

ansible_host = localhost
ansible_hostname = *undefined*
inventory_hostname = undercloud


ok: [centos-7-rax-iad-0001216943] => {}

MSG:

ansible_host = 192.168.24.4
ansible_hostname = *undefined*
inventory_hostname = centos-7-rax-iad-0001216943


ok: [centos-7-rax-iad-0001216958] => {}

MSG:

ansible_host = 192.168.24.3
ansible_hostname = *undefined*
inventory_hostname = centos-7-rax-iad-0001216958


TASK [values without gather_facts and with delegate_to: localhost] *****************************************************
Thursday 09 August 2018 10:51:20 +0100 (0:00:00.081) 0:00:00.136 *******
ok: [centos-7-rax-iad-0001216943 -> localhost] => {}

MSG:

ansible_host = 192.168.24.4
ansible_hostname = *undefined*
inventory_hostname = centos-7-rax-iad-0001216943


ok: [undercloud -> localhost] => {}

MSG:

ansible_host = localhost
ansible_hostname = *undefined*
inventory_hostname = undercloud


ok: [centos-7-rax-iad-0001216958 -> localhost] => {}

MSG:

ansible_host = 192.168.24.3
ansible_hostname = *undefined*
inventory_hostname = centos-7-rax-iad-0001216958


PLAY [localhost] *******************************************************************************************************
TASK [looping example run on localhost] ********************************************************************************
Thursday 09 August 2018 10:51:20 +0100 (0:00:00.059) 0:00:00.196 *******
ok: [localhost] => (item=None) => {}

MSG:

ansible_host = 127.0.0.1
ansible_hostname = *undefined*
inventory_hostname = localhost
hostvars['centos-7-rax-iad-0001216943']['ansible_hostname'] = *undefined*
hostvars['centos-7-rax-iad-0001216943']['ansible_host'] = 192.168.24.4
hostvars['centos-7-rax-iad-0001216943']['inventory_hostname'] = centos-7-rax-iad-0001216943


ok: [localhost] => (item=None) => {}

MSG:

ansible_host = 127.0.0.1
ansible_hostname = *undefined*
inventory_hostname = localhost
hostvars['undercloud']['ansible_hostname'] = *undefined*
hostvars['undercloud']['ansible_host'] = localhost
hostvars['undercloud']['inventory_hostname'] = undercloud


ok: [localhost] => (item=None) => {}

MSG:

ansible_host = 127.0.0.1
ansible_hostname = *undefined*
inventory_hostname = localhost
hostvars['centos-7-rax-iad-0001216958']['ansible_hostname'] = *undefined*
hostvars['centos-7-rax-iad-0001216958']['ansible_host'] = 192.168.24.3
hostvars['centos-7-rax-iad-0001216958']['inventory_hostname'] = centos-7-rax-iad-0001216958


PLAY RECAP *************************************************************************************************************
centos-7-rax-iad-0001216943 : ok=2  changed=0 unreachable=0 failed=0
centos-7-rax-iad-0001216958 : ok=2  changed=0 unreachable=0 failed=0
localhost : ok=1  changed=0 unreachable=0 failed=0
undercloud : ok=2  changed=0 unreachable=0 failed=0
Thursday 09 August 2018 10:51:20 +0100 (0:00:00.070) 0:00:00.267 *******
===============================================================================
values without gather_facts ------------------------------------------------------------------------------------- 0.08s
looping example run on localhost -------------------------------------------------------------------------------- 0.07s
values without gather_facts and with delegate_to: localhost ----------------------------------------------------- 0.06s
Playbook run took 0 days, 0 hours, 0 minutes, 0 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment