Skip to content

Commit 7c33a5d

Browse files
committed
rewriting this to work differently
1 parent 6bb42f5 commit 7c33a5d

137 files changed

Lines changed: 240 additions & 142 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

roles/collect_async_status/README.md

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,66 +8,42 @@ This is an internal role that is not meant to be called directly by users of thi
88

99
## Task Files
1010

11-
The role provides composable task files. `main.yml` loops over a configurable list of task files to include, so callers can control exactly which steps run and avoid unnecessary output.
12-
13-
### Available task files
14-
15-
|Task File|Description|Self-guarded|
16-
|:---|:---|:---:|
17-
|`collect_async_status.yml`|Polls `async_status` until the async job completes. Registers the result in `__cas_job_async_result`. Uses `failed_when: false` so subsequent task files can inspect the result.|no|
18-
|`register_value.yml`|Registers the async result into a caller-specified variable. Only runs when `aap_configuration_register` or the item's `register` field is defined.|yes|
19-
|`handle_error.yml`|Handles failed async results. Only runs when `__cas_job_async_result` is failed. In fail-fast mode (default), fails immediately with the error message and API response detail. In log-collection mode (`aap_configuration_collect_logs: true`), collects errors into `aap_configuration_role_errors` and continues.|yes|
20-
21-
### Controlling which task files run
11+
|Task File|Description|
12+
|:---|:---|
13+
|`collect_async_status.yml`|Polls `async_status` until the async job completes. If `cas_collect_errors` is `true` and the result failed, automatically includes `handle_error.yml`.|
14+
|`handle_error.yml`|Handles failed async results. In fail-fast mode (default), fails immediately. In log-collection mode (`aap_configuration_collect_logs: true`), collects errors into `aap_configuration_role_errors` and continues.|
15+
|`register_value.yml`|Registers the async result into a caller-specified variable. Only runs when `aap_configuration_register` or the item's `register` field is defined.|
2216

23-
`main.yml` iterates over the `cas_task_files` list variable. The default is:
17+
### Enabling error collection
2418

25-
```yaml
26-
cas_task_files:
27-
- collect_async_status.yml
28-
- handle_error.yml
29-
```
19+
Error handling via `handle_error.yml` is only included when `cas_collect_errors` is `true`. Each calling role passes its own `<prefix>_collect_errors` variable, which defaults to the global `aap_configuration_collect_errors`:
3020

31-
Files are included in list order. Each file is self-guarded (has its own `when` conditions), so it is safe to include files that may not apply — they will skip cleanly.
21+
- **Per-role**: Set `<prefix>_collect_errors: true` (e.g. `controller_configuration_applications_collect_errors: true`)
22+
- **Global**: Set `aap_configuration_collect_errors: true` to enable error handling for all roles
3223

33-
To customize, pass `cas_task_files` in the caller's `vars`:
24+
When `cas_collect_errors` is `false` (default), the `handle_error.yml` include is skipped entirely, keeping output clean.
3425

3526
```yaml
36-
# Only poll, no error handling (caller handles errors itself)
37-
- ansible.builtin.include_role:
38-
name: infra.aap_configuration.collect_async_status
39-
vars:
40-
cas_task_files:
41-
- collect_async_status.yml
42-
43-
# Poll + register + error handling
4427
- ansible.builtin.include_role:
4528
name: infra.aap_configuration.collect_async_status
29+
loop: "{{ __job_async.results }}"
4630
vars:
47-
cas_task_files:
48-
- collect_async_status.yml
49-
- register_value.yml
50-
- handle_error.yml
51-
```
52-
53-
Individual files can also be included directly using `tasks_from`:
54-
55-
```yaml
56-
- ansible.builtin.include_role:
57-
name: infra.aap_configuration.collect_async_status
58-
tasks_from: collect_async_status.yml
31+
cas_collect_errors: "{{ controller_configuration_applications_collect_errors }}"
32+
cas_job_async_results_item: "{{ __job_async_results_item }}"
33+
# ... other vars ...
5934
```
6035

6136
## Variables
6237

6338
|Variable Name|Default Value|Required|Description|
6439
|:---|:---:|:---:|:---|
6540
|`cas_job_async_results_item`||yes|The asynchronous item to check the status of. This must be from the registered `async` task|
66-
|`cas_task_files`|`[collect_async_status.yml, handle_error.yml]`|no|Ordered list of task files to include. Controls which steps run and their order.|
41+
|`cas_collect_errors`|`{{ aap_configuration_collect_errors \| default(false) }}`|no|When `true` and the async result has failed, `collect_async_status.yml` automatically includes `handle_error.yml`. Each calling role passes its own `<prefix>_collect_errors` variable.|
6742
|`cas_error_list_var_name`||yes|The name of the dictionary key to use when collecting errors|
6843
|`cas_register_subvar`||yes|The name of the dictionary key to use when registering values|
6944
|`cas_object_label`||no|Custom task label for the async_status polling task. When provided, replaces the default task name for better output readability.|
7045
|`cas_collect_logs`|`{{ aap_configuration_collect_logs \| default(false) }}`|no|When `true`, async task failures are suppressed (`failed_when: false`) so that `handle_error.yml` can collect error details and continue execution. Errors are collected in `aap_configuration_role_errors`. When `false` (default), the async task fails immediately on error.|
46+
|`aap_configuration_collect_errors`|`false`|no|Global toggle to enable error collection for all roles. Each role's `<prefix>_collect_errors` defaults to this value.|
7147

7248
### Error Output
7349

roles/collect_async_status/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ cas_async_retries: "{{ aap_configuration_async_retries | default(50) }}"
33
cas_async_delay: "{{ aap_configuration_async_delay | default(1) }}"
44
cas_secure_logging: "{{ aap_configuration_secure_logging | default('false') }}"
55
cas_collect_logs: "{{ aap_configuration_collect_logs | default(false) }}"
6+
cas_collect_errors: "{{ aap_configuration_collect_errors | default(false) }}"
67
...

roles/collect_async_status/tasks/collect_async_status.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

roles/collect_async_status/tasks/handle_error.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
- name: handle_error | Handle Errors Block
3-
when: __cas_job_async_result is defined and __cas_job_async_result is failed
4-
no_log: "{{ cas_secure_logging }}"
3+
when: __cas_job_async_result is defined and __cas_job_async_result.status is defined and __cas_job_async_result.status == 'failed'
54
block:
65
- name: handle_error | Show error and stop execution
7-
when: not cas_collect_logs | bool
6+
no_log: "{{ cas_secure_logging }}"
7+
when: not (cas_collect_logs | bool or cas_collect_errors | bool)
88
vars:
99
__cas_response: "{{ __cas_job_async_result['response'] | default({}) }}"
1010
__cas_response_detail: >-
@@ -43,6 +43,7 @@
4343
}}
4444
4545
- name: handle_error | Build consolidated list of failed objects and the error
46+
no_log: "{{ cas_secure_logging }}"
4647
vars:
4748
__cas_response: "{{ __cas_job_async_result['response'] | default({}) }}"
4849
__new_error: >-
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
---
2-
- name: Include async status tasks
2+
- name: "{{ cas_object_label | default('collect_async_status | Wait for async job to complete') }}"
3+
no_log: "{{ cas_secure_logging }}"
4+
ansible.builtin.async_status:
5+
jid: "{{ cas_job_async_results_item.ansible_job_id }}"
6+
register: __cas_job_async_result
7+
until: __cas_job_async_result.finished
8+
retries: "{{ cas_async_retries }}"
9+
delay: "{{ cas_async_delay }}"
10+
failed_when: __cas_job_async_result is failed and not (cas_collect_logs | bool or cas_collect_errors | bool)
11+
12+
- name: "Handle errors"
13+
when: cas_collect_errors | bool and __cas_job_async_result is defined and __cas_job_async_result.status is defined and __cas_job_async_result.status == 'failed'
314
ansible.builtin.include_tasks:
4-
file: "{{ __cas_task_file }}"
5-
loop: "{{ cas_task_files | default(__cas_default_task_files) }}"
6-
loop_control:
7-
loop_var: __cas_task_file
8-
label: "{{ __cas_task_file }}"
9-
vars:
10-
__cas_default_task_files:
11-
- collect_async_status.yml
12-
- handle_error.yml
15+
file: handle_error.yml
1316
...

roles/collect_async_status/tasks/register_value.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

roles/controller_applications/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ controller_configuration_applications_async_delay: "{{ aap_configuration_async_d
77
controller_configuration_applications_loop_delay: "{{ aap_configuration_loop_delay | default(0) }}"
88
aap_configuration_async_dir:
99
controller_configuration_applications_enforce_defaults: "{{ aap_configuration_enforce_defaults | default(false) }}"
10+
controller_configuration_applications_collect_errors: "{{ aap_configuration_collect_errors | default(false) }}"
1011
...

roles/controller_applications/tasks/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
- name: Manage Controller Applications Block
44
vars:
55
ansible_async_dir: "{{ aap_configuration_async_dir }}"
6-
no_log: "{{ controller_configuration_applications_secure_logging }}"
76
block:
87
- name: Managing Controller Applications
8+
no_log: "{{ controller_configuration_applications_secure_logging }}"
99
ansible.controller.application:
1010
name: "{{ __application_item.name | mandatory }}"
1111
new_name: "{{ __application_item.new_name | default(omit, true) }}"
@@ -53,6 +53,7 @@
5353
label: "{{ __operation.verb }} Controller Application {{ __applications_job_async_results_item.__application_item.name }} | Wait for finish the Application {{
5454
__operation.action }}"
5555
vars:
56+
cas_collect_errors: "{{ controller_configuration_applications_collect_errors }}"
5657
cas_secure_logging: "{{ controller_configuration_applications_secure_logging }}"
5758
cas_async_delay: "{{ controller_configuration_applications_async_delay }}"
5859
cas_async_retries: "{{ controller_configuration_applications_async_retries }}"

roles/controller_bulk_host_create/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ controller_configuration_bulk_hosts_async_retries: "{{ aap_configuration_async_r
44
controller_configuration_bulk_hosts_async_delay: "{{ aap_configuration_async_delay | default(1) }}"
55
controller_configuration_bulk_hosts_loop_delay: "{{ aap_configuration_loop_delay | default(0) }}"
66
aap_configuration_async_dir:
7+
controller_configuration_bulk_hosts_collect_errors: "{{ aap_configuration_collect_errors | default(false) }}"
78
...

roles/controller_bulk_host_create/tasks/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
- name: Manage Controller hosts in bulk Block
33
vars:
44
ansible_async_dir: "{{ aap_configuration_async_dir }}"
5-
no_log: "{{ controller_configuration_bulk_hosts_secure_logging }}"
65
block:
76
# Create controller hosts
87
- name: Add Controller hosts in bulk
8+
no_log: "{{ controller_configuration_bulk_hosts_secure_logging }}"
99
ansible.controller.bulk_host_create:
1010
hosts: "{{ __controller_bulk_hosts_item.hosts }}"
1111
inventory: "{{ __controller_bulk_hosts_item.inventory }}"
@@ -41,6 +41,7 @@
4141
loop_control:
4242
loop_var: __controller_bulk_hosts_job_async_results_item
4343
vars:
44+
cas_collect_errors: "{{ controller_configuration_bulk_hosts_collect_errors }}"
4445
cas_secure_logging: "{{ controller_configuration_bulk_hosts_secure_logging }}"
4546
cas_async_delay: "{{ controller_configuration_bulk_hosts_async_delay }}"
4647
cas_async_retries: "{{ controller_configuration_bulk_hosts_async_retries }}"

0 commit comments

Comments
 (0)