Skip to content

Instantly share code, notes, and snippets.

@willthames
Last active August 29, 2015 13:57
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 willthames/9614054 to your computer and use it in GitHub Desktop.
Save willthames/9614054 to your computer and use it in GitHub Desktop.
Accidentally defining a group containing a group as a group containing a host raises no error (even though there will be a host and a group with the same names).
[group-a:children]
group-b
# here group-c is actually a host because of the missing :children
[group-b]
group-c
# as a result, host-c is also a host, but doesn't belong to group-b (or group-a)
[group-c]
host-c
[group-b:vars]
group_b_var=group-b
[group-a:children]
group-b
# now group-c is a group, not a host
[group-b:children]
group-c
# as a result, host-c now correctly belongs to group-b (or group-a)
[group-c]
host-c
[group-b:vars]
group_b_var=group-b
- hosts: host-c
connection: local
gather_facts: False
tasks:
- name: print variable
action: debug msg="{{group_b_var}}"
$ ansible-playbook playbook.yml -i hosts.correct
PLAY [host-c] *****************************************************************
TASK: [print variable] ********************************************************
ok: [host-c] => {
"msg": "group-b"
}
PLAY RECAP ********************************************************************
host-c : ok=1 changed=0 unreachable=0 failed=0
$ ansible-playbook playbook.yml -i hosts
PLAY [host-c] *****************************************************************
TASK: [print variable] ********************************************************
fatal: [host-c] => One or more undefined variables: 'group_b_var' is undefined
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/home/will/playbook.retry
host-c : ok=0 changed=0 unreachable=1 failed=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment