Exclude unreachable hosts in ansible_play_batch between plays (#74625)
ci_complete
This commit is contained in:
parent
df6554c4ec
commit
cf11c38caf
6 changed files with 68 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- Save unreachable hosts between plays by adding them to the PlayIterator's _play._removed_hosts (https://github.com/ansible/ansible/issues/66945).
|
|
@ -301,6 +301,8 @@ class TaskQueueManager:
|
||||||
for host_name in self._failed_hosts.keys():
|
for host_name in self._failed_hosts.keys():
|
||||||
host = self._inventory.get_host(host_name)
|
host = self._inventory.get_host(host_name)
|
||||||
iterator.mark_host_failed(host)
|
iterator.mark_host_failed(host)
|
||||||
|
for host_name in self._unreachable_hosts.keys():
|
||||||
|
iterator._play._removed_hosts.append(host_name)
|
||||||
|
|
||||||
self.clear_failed_hosts()
|
self.clear_failed_hosts()
|
||||||
|
|
||||||
|
|
1
test/integration/targets/special_vars_hosts/aliases
Normal file
1
test/integration/targets/special_vars_hosts/aliases
Normal file
|
@ -0,0 +1 @@
|
||||||
|
shippable/posix/group5
|
3
test/integration/targets/special_vars_hosts/inventory
Normal file
3
test/integration/targets/special_vars_hosts/inventory
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
successful ansible_connection=local ansible_host=127.0.0.1 ansible_python_interpreter="{{ ansible_playbook_python }}"
|
||||||
|
failed ansible_connection=local ansible_host=127.0.0.1 ansible_python_interpreter="{{ ansible_playbook_python }}"
|
||||||
|
unreachable ansible_connection=ssh ansible_host=127.0.0.1 ansible_port=1011 # IANA Reserved port
|
53
test/integration/targets/special_vars_hosts/playbook.yml
Normal file
53
test/integration/targets/special_vars_hosts/playbook.yml
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
gather_facts: no
|
||||||
|
tasks:
|
||||||
|
- name: test magic vars for hosts without any failed/unreachable (no serial)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- ansible_play_batch | length == 3
|
||||||
|
- ansible_play_hosts | length == 3
|
||||||
|
- ansible_play_hosts_all | length == 3
|
||||||
|
run_once: True
|
||||||
|
|
||||||
|
- ping:
|
||||||
|
failed_when: "inventory_hostname == 'failed'"
|
||||||
|
|
||||||
|
- meta: clear_host_errors
|
||||||
|
|
||||||
|
- hosts: all
|
||||||
|
gather_facts: no
|
||||||
|
tasks:
|
||||||
|
- name: test host errors were cleared
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- ansible_play_batch | length == 3
|
||||||
|
- ansible_play_hosts | length == 3
|
||||||
|
- ansible_play_hosts_all | length == 3
|
||||||
|
run_once: True
|
||||||
|
|
||||||
|
- ping:
|
||||||
|
failed_when: "inventory_hostname == 'failed'"
|
||||||
|
|
||||||
|
- name: test magic vars exclude failed/unreachable hosts
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- ansible_play_batch | length == 1
|
||||||
|
- ansible_play_hosts | length == 1
|
||||||
|
- "ansible_play_batch == ['successful']"
|
||||||
|
- "ansible_play_hosts == ['successful']"
|
||||||
|
- ansible_play_hosts_all | length == 3
|
||||||
|
run_once: True
|
||||||
|
|
||||||
|
- hosts: all
|
||||||
|
gather_facts: no
|
||||||
|
tasks:
|
||||||
|
- name: test failed/unreachable persists between plays
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- ansible_play_batch | length == 1
|
||||||
|
- ansible_play_hosts | length == 1
|
||||||
|
- "ansible_play_batch == ['successful']"
|
||||||
|
- "ansible_play_hosts == ['successful']"
|
||||||
|
- ansible_play_hosts_all | length == 3
|
||||||
|
run_once: True
|
7
test/integration/targets/special_vars_hosts/runme.sh
Executable file
7
test/integration/targets/special_vars_hosts/runme.sh
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
ansible-playbook -i ./inventory playbook.yml "$@" | tee out.txt
|
||||||
|
grep 'unreachable=2' out.txt
|
||||||
|
grep 'failed=2' out.txt
|
Loading…
Reference in a new issue