mirror of https://github.com/ansible/ansible.git
Fix include_role error consitency and add rescueable option (#86012)
* include_role now behaves more like task on error changes _from errors from syntax to task failures, by default which makes it more consistent with other existing errors * also force 'missing role' to behave as syntax error when false * also error when subdir does not exist, previouslly we ignored missing file * add 'rescuable' toggle to allow user to chose error type Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com> Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com>pull/81320/head
parent
1cb2932c95
commit
ccfb7b1364
@ -0,0 +1,5 @@
|
|||||||
|
minor_changes:
|
||||||
|
- include_role has new option `rescuable` to allow it to toggle between task failure and syntax errors.
|
||||||
|
bugfixes:
|
||||||
|
- include_role would emit a syntax error on X_from options errors, but a task failure when missing a role to make it consistent now it also emits a task failure on missing tasks_from, which makes it subject to error handling in the play.
|
||||||
|
- include_role, would ignore missing X_from files if the subdir (tasks/vars/handlers/defaults) did not exist, now it is a proper error.
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
- hosts: localhost
|
||||||
|
gather_facts: no
|
||||||
|
tasks:
|
||||||
|
- import_role:
|
||||||
|
name: test_includes
|
||||||
|
rescuable: true
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
- hosts: localhost
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: test missing role rescue
|
||||||
|
vars:
|
||||||
|
rescue_1: false
|
||||||
|
block:
|
||||||
|
- name: Include a role that doesn't exist
|
||||||
|
include_role:
|
||||||
|
name: missing_role
|
||||||
|
rescuable: '{{ rescueme | default(omit) }}'
|
||||||
|
|
||||||
|
rescue:
|
||||||
|
- set_fact:
|
||||||
|
rescue_1: true
|
||||||
|
always:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- rescue_1 == rescueme|default(True)
|
||||||
|
|
||||||
|
- name: Test _from rescue
|
||||||
|
vars:
|
||||||
|
rescue_2: false
|
||||||
|
block:
|
||||||
|
- name: Include a task file that doesn't exist, but role exists
|
||||||
|
include_role:
|
||||||
|
name: include_roles
|
||||||
|
tasks_from: missing_task_list
|
||||||
|
rescuable: '{{ rescueme | default(omit) }}'
|
||||||
|
|
||||||
|
rescue:
|
||||||
|
- set_fact:
|
||||||
|
rescue_2: true
|
||||||
|
always:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- rescue_2 == rescueme|default(True)
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
- hosts: localhost
|
||||||
|
gather_facts: no
|
||||||
|
tasks:
|
||||||
|
- file:
|
||||||
|
path: roles/rolename
|
||||||
|
state: "{{ item }}"
|
||||||
|
loop:
|
||||||
|
- absent
|
||||||
|
- directory
|
||||||
|
|
||||||
|
- name: ensure we fail when missing both file and tasks/ subdir
|
||||||
|
block:
|
||||||
|
- include_role:
|
||||||
|
name: rolename
|
||||||
|
tasks_from: missing.yml
|
||||||
|
rescue:
|
||||||
|
- set_fact:
|
||||||
|
wefailed: True
|
||||||
|
always:
|
||||||
|
- name: check we actually failed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- wefailed is defined
|
||||||
|
- wefailed
|
||||||
Loading…
Reference in New Issue