Skip to content

Instantly share code, notes, and snippets.

@manicminer
Created October 29, 2014 12:06
Show Gist options
  • Save manicminer/de2a9e3f07a826e50203 to your computer and use it in GitHub Desktop.
Save manicminer/de2a9e3f07a826e50203 to your computer and use it in GitHub Desktop.
ansible limit test with host facts
$ 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
$ 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
[group1]
host1
[group2]
host2
{% for host in groups['group2'] %}
{{ hostvars[host]['ansible_default_ipv4']['address'] }}
{% endfor %}
- 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