Skip to content

Instantly share code, notes, and snippets.

@mageddo
Created January 26, 2019 16:30
Show Gist options
  • Save mageddo/5a4033272ba07c25d6b76723b1785693 to your computer and use it in GitHub Desktop.
Save mageddo/5a4033272ba07c25d6b76723b1785693 to your computer and use it in GitHub Desktop.
Acessing inventory hosts inside playbook
$ ansible-playbook -i hosts -c local playbook.yml 

PLAY [main[0]] *******************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
ok: [127.0.0.1]

TASK [debug] *********************************************************************************************************************************************************************************************************************************
ok: [127.0.0.1] => {
    "msg": "192.168.0.53"
}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
127.0.0.1                  : ok=2    changed=0    unreachable=0    failed=0   
[main]
127.0.0.1
192.168.0.53
- hosts: main[0]
tasks:
- debug:
msg: "{{ groups['main'][1] }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment