Hi,
I have following playbook, which I expect it to run only once, on one of the `group2` hosts.
site.yml
---
- hosts:
- group1
- group2
roles:
- { role: test }
roles/test/tasks/main.yml
---
- include: test.yml
when: inventory_hostname in groups['group2']
roles/test/tasks/test.yml
---
- name: test - include together with run_once
debug: var='abc'
run_once: true
However, after skipping the `host1` from group1 (since it is the first in site.yml), it never run on host2.
$ ansible-playbook -i test_inventory site.yml
PLAY [group1;group2] **********************************************************
GATHERING FACTS ***************************************************************
ok: [host1]
ok: [host2]
TASK: [test | test - include together with run_once] **************************
skipping: [host1]
PLAY RECAP ********************************************************************
host1 : ok=1 changed=0 unreachable=0 failed=0
host2 : ok=1 changed=0 unreachable=0 failed=0
# cat test_inventory
[group1]
host1
[group2]
host2
Does that mean `run_once` and `when` better not to be used together? Shouldn't that `include: test.yml` only executed when `inventory_hostname in groups['group2']` satisfied? Some pointer or explanation would be highly appreciated.
Thanks,
QY