Last active
August 29, 2015 13:57
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: host-c | |
connection: local | |
gather_facts: False | |
tasks: | |
- name: print variable | |
action: debug msg="{{group_b_var}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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