mirror of https://github.com/ansible/ansible.git
parent
fe7e68bfcb
commit
89137cb5a0
@ -0,0 +1,2 @@
|
||||
minor_changes:
|
||||
- Add a new meta task ``end_role`` (https://github.com/ansible/ansible/issues/22286)
|
@ -0,0 +1,35 @@
|
||||
- hosts: localhost
|
||||
gather_facts: false
|
||||
pre_tasks:
|
||||
- set_fact:
|
||||
play_checkpoint: 1
|
||||
roles:
|
||||
- end_role_inside
|
||||
tasks:
|
||||
- set_fact:
|
||||
play_checkpoint: "{{ play_checkpoint|int + 1 }}"
|
||||
|
||||
- import_role:
|
||||
name: end_role_inside
|
||||
allow_duplicates: true
|
||||
|
||||
- set_fact:
|
||||
play_checkpoint: "{{ play_checkpoint|int + 1 }}"
|
||||
|
||||
- include_role:
|
||||
name: end_role_inside
|
||||
allow_duplicates: false
|
||||
|
||||
- set_fact:
|
||||
play_checkpoint: "{{ play_checkpoint|int + 1 }}"
|
||||
post_tasks:
|
||||
- assert:
|
||||
that:
|
||||
- role_executed|int == 2
|
||||
- after_end_role is undefined
|
||||
- play_checkpoint|int == 4
|
||||
- role_handler_ran is defined
|
||||
|
||||
- name: when running this playbook check this appears on stdout to ensure the above assert wasn't skipped
|
||||
debug:
|
||||
msg: CHECKPOINT
|
@ -0,0 +1,9 @@
|
||||
- hosts: localhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- debug:
|
||||
changed_when: true
|
||||
notify: invalid_handler
|
||||
handlers:
|
||||
- name: invalid_handler
|
||||
meta: end_role
|
@ -0,0 +1,6 @@
|
||||
- hosts: host1,host2
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- include_role:
|
||||
name: end_role_inside
|
||||
tasks_from: nested.yml
|
@ -0,0 +1,3 @@
|
||||
- name: role_handler
|
||||
set_fact:
|
||||
role_handler_ran: true
|
@ -0,0 +1,10 @@
|
||||
- set_fact:
|
||||
role_executed: "{{ role_executed|default(0)|int + 1 }}"
|
||||
|
||||
- command: echo
|
||||
notify: role_handler
|
||||
|
||||
- meta: end_role
|
||||
|
||||
- set_fact:
|
||||
after_end_role: true
|
@ -0,0 +1,22 @@
|
||||
- set_fact:
|
||||
end_role_cond: "{{ inventory_hostname == 'host1' }}"
|
||||
|
||||
- include_role:
|
||||
name: end_role_inside_nested
|
||||
|
||||
- debug:
|
||||
msg: CHECKPOINT
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- after_end_role is undefined
|
||||
when: inventory_hostname == "host1"
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- after_end_role
|
||||
when: inventory_hostname == "host2"
|
||||
|
||||
- name: when running this playbook check this appears on stdout to ensure the above assert wasn't skipped
|
||||
debug:
|
||||
msg: CHECKPOINT
|
@ -0,0 +1,5 @@
|
||||
- meta: end_role
|
||||
when: end_role_cond
|
||||
|
||||
- set_fact:
|
||||
after_end_role: true
|
@ -0,0 +1 @@
|
||||
- import_tasks: import_tasks.yml
|
@ -0,0 +1 @@
|
||||
- include_tasks: include_tasks.yml
|
Loading…
Reference in New Issue