Created
October 29, 2014 12:06
-
-
Save manicminer/de2a9e3f07a826e50203 to your computer and use it in GitHub Desktop.
ansible limit test with host facts
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 -i test.ini test.yml --limit group1 | |
PLAY [all] ******************************************************************** | |
GATHERING FACTS *************************************************************** | |
ok: [group1] | |
TASK: [command true] ********************************************************** | |
changed: [host1] | |
PLAY [group1] ***************************************************************** | |
GATHERING FACTS *************************************************************** | |
ok: [host1] | |
TASK: [template src=test.j2 dest=/tmp/test] *********************************** | |
fatal: [host1] => {'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'dict object' has no attribute 'ansible_default_ipv4'", 'failed': True} | |
fatal: [host1] => {'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'dict object' has no attribute 'ansible_default_ipv4'", 'failed': True} | |
FATAL: all hosts have already failed -- aborting | |
PLAY RECAP ******************************************************************** | |
to retry, use: --limit @/Users/tom/test.retry | |
host1 : ok=3 changed=1 unreachable=1 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 -i test.ini test.yml | |
PLAY [all] ******************************************************************** | |
GATHERING FACTS *************************************************************** | |
ok: [host1] | |
ok: [host2] | |
TASK: [command true] ********************************************************** | |
changed: [host1] | |
changed: [host2] | |
PLAY [group1] ***************************************************************** | |
GATHERING FACTS *************************************************************** | |
ok: [host1] | |
TASK: [template src=test.j2 dest=/tmp/test] *********************************** | |
changed: [host1] | |
PLAY RECAP ******************************************************************** | |
host1 : ok=4 changed=2 unreachable=0 failed=0 | |
host2 : ok=2 changed=1 unreachable=0 failed=0 | |
$ ssh host1 cat /tmp/test | |
100.101.202.203 |
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
[group1] | |
host1 | |
[group2] | |
host2 |
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
{% for host in groups['group2'] %} | |
{{ hostvars[host]['ansible_default_ipv4']['address'] }} | |
{% endfor %} |
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: all | |
tasks: | |
- command: 'true' | |
- hosts: group1 | |
tasks: | |
- template: src=test.j2 dest=/tmp/test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment