Skip to content

Instantly share code, notes, and snippets.

@phips
Created June 16, 2014 17:57
Show Gist options
  • Save phips/2a51a5d32fdff4dcb719 to your computer and use it in GitHub Desktop.
Save phips/2a51a5d32fdff4dcb719 to your computer and use it in GitHub Desktop.
hostvars test fail
# {{ ansible_managed }}
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
{% for host in groups.all %}
{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }} {{ host }}
{% endfor %}
$ ansible-playbook site.yml --limit master
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [master]
TASK: [hosts | Ensure hostname set] *******************************************
ok: [master]
TASK: [hosts | DEBUG] *********************************************************
ok: [master] => {
"msg": "10.16.216.135"
}
TASK: [hosts | Ensure /etc/hosts populated] ***********************************
fatal: [master] => {'msg': "One or more undefined variables: 'dict object' has no attribute 'ansible_eth0'", 'failed': True}
fatal: [master] => {'msg': "One or more undefined variables: 'dict object' has no attribute 'ansible_eth0'", 'failed': True}
FATAL: all hosts have already failed -- aborting
$ ansible-playbook site.yml
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [master]
ok: [ansible-target]
TASK: [hosts | Ensure hostname set] *******************************************
ok: [ansible-target]
ok: [master]
TASK: [hosts | DEBUG] *********************************************************
ok: [master] => {
"msg": "10.16.216.135"
}
ok: [ansible-target] => {
"msg": "10.16.216.179"
}
TASK: [hosts | Ensure /etc/hosts populated] ***********************************
ok: [master]
ok: [ansible-target]
$ cat site.yml
---
- hosts: all
sudo: true
gather_facts: true
roles:
- hosts
- hosts: master
sudo: true
roles:
- ansible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment