|
| 1 | +--- |
| 2 | +# Task file: clear_facts, run linux-system-roles.ad_integration |
| 3 | +# Include this with include_tasks or import_tasks |
| 4 | +# Input: |
| 5 | +# - __sr_tasks_from: tasks_from to run - same as tasks_from in include_role |
| 6 | +# - __sr_public: export private vars from role - same as public in include_role |
| 7 | +# - __sr_failed_when: set to false to ignore role errors - same as failed_when in include_role |
| 8 | +- name: Clear facts |
| 9 | + meta: clear_facts |
| 10 | + |
| 11 | +# note that you can use failed_when with import_role but not with include_role |
| 12 | +# so this simulates the __sr_failed_when false case |
| 13 | +# Q: Why do we need a separate task to run the role normally? Why not just |
| 14 | +# run the role in the block and rethrow the error in the rescue block? |
| 15 | +# A: Because you cannot rethrow the error in exactly the same way as the role does. |
| 16 | +# It might be possible to exactly reconstruct ansible_failed_result but it's not worth the effort. |
| 17 | +- name: Run the role with __sr_failed_when false |
| 18 | + when: |
| 19 | + - __sr_failed_when is defined |
| 20 | + - not __sr_failed_when |
| 21 | + block: |
| 22 | + - name: Run the role |
| 23 | + include_role: |
| 24 | + name: linux-system-roles.ad_integration |
| 25 | + tasks_from: "{{ __sr_tasks_from | default('main') }}" |
| 26 | + public: "{{ __sr_public | default(false) }}" |
| 27 | + rescue: |
| 28 | + - name: Ignore the failure when __sr_failed_when is false |
| 29 | + debug: |
| 30 | + msg: Ignoring failure when __sr_failed_when is false |
| 31 | + |
| 32 | +- name: Run the role normally |
| 33 | + include_role: |
| 34 | + name: linux-system-roles.ad_integration |
| 35 | + tasks_from: "{{ __sr_tasks_from | default('main') }}" |
| 36 | + public: "{{ __sr_public | default(false) }}" |
| 37 | + when: __sr_failed_when | d(true) |
0 commit comments