mirror of https://github.com/ansible/ansible.git
* If all tasks in the role are skipped or unreachable, the role is not marked as complete for the host.
* Only mark the role as complete if a task in the role succeeds or fails for the host.
(cherry picked from commit 8034651cd2
)
pull/81828/head
parent
5888674946
commit
8f621fd6cd
@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- role deduplication - don't deduplicate before a role has had a task run for that particular host (https://github.com/ansible/ansible/issues/81486).
|
@ -0,0 +1,47 @@
|
|||||||
|
- name: test deduping allows for 1 successful execution of role after it is skipped
|
||||||
|
hosts: testhost
|
||||||
|
gather_facts: false
|
||||||
|
tags: [ 'conditional_skipped' ]
|
||||||
|
roles:
|
||||||
|
# Skipped the first time it executes
|
||||||
|
- role: a
|
||||||
|
when: role_set_var is defined
|
||||||
|
|
||||||
|
- role: set_var
|
||||||
|
|
||||||
|
# No longer skipped
|
||||||
|
- role: a
|
||||||
|
when: role_set_var is defined
|
||||||
|
# Deduplicated with the previous success
|
||||||
|
- role: a
|
||||||
|
when: role_set_var is defined
|
||||||
|
|
||||||
|
- name: test deduping allows for successful execution of role after host is unreachable
|
||||||
|
hosts: fake,testhost
|
||||||
|
gather_facts: false
|
||||||
|
tags: [ 'unreachable' ]
|
||||||
|
ignore_unreachable: yes
|
||||||
|
roles:
|
||||||
|
# unreachable by the first host
|
||||||
|
- role: test_connectivity
|
||||||
|
|
||||||
|
# unreachable host will try again,
|
||||||
|
# the successful host will not because it's deduplicated
|
||||||
|
- role: test_connectivity
|
||||||
|
|
||||||
|
- name: test deduping role for failed host
|
||||||
|
hosts: testhost,localhost
|
||||||
|
gather_facts: false
|
||||||
|
tags: [ 'conditional_failed' ]
|
||||||
|
ignore_errors: yes
|
||||||
|
roles:
|
||||||
|
# Uses run_once to fail on the first host the first time it executes
|
||||||
|
- role: failed_when
|
||||||
|
|
||||||
|
- role: set_var
|
||||||
|
- role: recover
|
||||||
|
|
||||||
|
# Deduplicated after the failure, ONLY runs for localhost
|
||||||
|
- role: failed_when
|
||||||
|
# Deduplicated with the previous success
|
||||||
|
- role: failed_when
|
@ -0,0 +1,4 @@
|
|||||||
|
- debug:
|
||||||
|
msg: "{{ role_set_var is undefined | ternary('failed_when task failed', 'failed_when task succeeded') }}"
|
||||||
|
failed_when: role_set_var is undefined
|
||||||
|
run_once: true
|
@ -0,0 +1 @@
|
|||||||
|
- meta: clear_host_errors
|
@ -0,0 +1,2 @@
|
|||||||
|
- set_fact:
|
||||||
|
role_set_var: true
|
@ -0,0 +1,2 @@
|
|||||||
|
- ping:
|
||||||
|
data: 'reachable'
|
Loading…
Reference in New Issue