Refactor async task handling

- Standardize async/poll usage with 'ASYNC_ENABLED | bool'
- Add async/poll parameters to Cloudflare, Nginx, Mailu, MIG, Nextcloud, and OpenLDAP tasks
- Update async configuration in 'group_vars/all/00_general.yml' to ensure boolean evaluation
- Allow CAA, cache, and DNS tasks to run asynchronously when enabled

https://chatgpt.com/share/689cd8cc-7fbc-800f-bd06-a667561573bf
This commit is contained in:
Kevin Veen-Birkenbach 2025-08-13 21:56:26 +02:00
parent 597e9d5222
commit c729edb525
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
16 changed files with 53 additions and 30 deletions

View File

@ -66,8 +66,8 @@ DOCKER_VARS_FILE: "{{ playbook_dir }}/roles/docker-compo
# Asyn Confitguration
ASYNC_ENABLED: "{{ not MODE_DEBUG | bool }}" # Activate async, deactivated for debugging
ASYNC_TIME: "{{ 300 if ASYNC_ENABLED else omit }}" # Run for mnax 5min
ASYNC_POLL: "{{ 0 if ASYNC_ENABLED else 10 }}" # Don't wait for task
ASYNC_TIME: "{{ 300 if ASYNC_ENABLED | bool else omit }}" # Run for mnax 5min
ASYNC_POLL: "{{ 0 if ASYNC_ENABLED | bool else 10 }}" # Don't wait for task
# default value if not set via CLI (-e) or in playbook vars
allowed_applications: []

View File

@ -24,3 +24,4 @@ nginx:
general: "/tmp/cache_nginx_general/" # Directory which nginx uses to cache general data
image: "/tmp/cache_nginx_image/" # Directory which nginx uses to cache images
user: "http" # Default nginx user in ArchLinux

View File

@ -9,4 +9,5 @@
purge_everything: true
body_format: json
return_content: yes
register: cf_purge
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"

View File

@ -14,6 +14,7 @@
Content-Type: "application/json"
return_content: yes
register: cf_dev_mode_current
when: ASYNC_ENABLED | bool
- name: "Enable Cloudflare Development Mode"
ansible.builtin.uri:
@ -28,5 +29,8 @@
return_content: yes
register: cf_dev_mode_enable
changed_when: >
ASYNC_ENABLED | bool and
cf_dev_mode_current.json.result.value is defined and
cf_dev_mode_current.json.result.value != 'on'
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"

View File

@ -47,9 +47,12 @@
mode: '0755'
loop: >
{{ nginx.directories.data.values() | list }}
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
- name: "Include tasks to create cache directories"
include_tasks: 03_cache_directories.yml
when: run_once_nginx_reverse_proxy is not defined
- name: create nginx config file
template:

View File

@ -5,7 +5,6 @@
state: absent
when:
- MODE_CLEANUP | bool
- run_once_nginx_reverse_proxy is not defined
loop: "{{ nginx.directories.cache | dict2items }}"
loop_control:
label: "{{ item.key }}"
@ -18,13 +17,12 @@
owner: "{{ nginx.user }}"
group: "{{ nginx.user }}"
mode: '0700'
when: run_once_nginx_reverse_proxy is not defined
loop: "{{ nginx.directories.cache | dict2items }}"
loop_control:
label: "{{ item.key }}"
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
- name: run the nginx_reverse_proxy tasks once
set_fact:
run_once_nginx_reverse_proxy: true
when: run_once_nginx_reverse_proxy is not defined

View File

@ -20,3 +20,5 @@
loop: "{{ base_sld_domains | product(caa_entries) | list }}"
loop_control:
label: "{{ item.0 }} → {{ item.1.tag }}"
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"

View File

@ -18,8 +18,8 @@
uidNumber: "{{ item.value.uid | int }}"
gidNumber: "{{ item.value.gid | int }}"
state: present # ↳ creates but never updates
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
loop: "{{ users | dict2items }}"
loop_control:
label: "{{ item.key }}"
@ -37,8 +37,8 @@
objectClass: "{{ ldap.user.objects.structural }}"
mail: "{{ item.value.email }}"
state: exact
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
loop: "{{ users | dict2items }}"
loop_control:
label: "{{ item.key }}"

View File

@ -21,8 +21,8 @@
attributes:
objectClass: "{{ missing_auxiliary }}"
state: present
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
loop: "{{ ldap_users_with_classes.results }}"
loop_control:
label: "{{ item.dn }}"

View File

@ -14,6 +14,8 @@
proxied: false
ttl: 1
state: present
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
- name: "Set CNAME record for autoconfig"
community.general.cloudflare_dns:
@ -25,6 +27,8 @@
proxied: false
ttl: 1
state: present
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
- name: "Set MX record"
community.general.cloudflare_dns:
@ -36,6 +40,8 @@
priority: 10
ttl: 1
state: present
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
- name: "Set SRV records"
community.general.cloudflare_dns:
@ -55,6 +61,8 @@
#register: srv_result
#failed_when: srv_result.rc != 0 and ("An identical record already exists" not in srv_result.stdout)
#changed_when: srv_result.rc == 0 and ("An identical record already exists" not in srv_result.stdout)
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
- name: "Set SPF TXT record"
community.general.cloudflare_dns:
@ -65,6 +73,8 @@
value: "v=spf1 mx a:{{ domain }} ~all"
ttl: 1
state: present
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
- name: "Set DMARC TXT record"
community.general.cloudflare_dns:
@ -75,6 +85,8 @@
value: "v=DMARC1; p=reject; ruf=mailto:{{ mailu_dmarc_ruf }}; adkim=s; aspf=s"
ttl: 1
state: present
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
- name: "Set DKIM TXT record"
community.general.cloudflare_dns:
@ -85,3 +97,5 @@
value: "{{ mailu_dkim_public_key }}"
ttl: 1
state: present
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"

View File

@ -3,8 +3,8 @@
set -euo pipefail
infinito build tree --no-signal --alarm-timeout 0 -s {{ mig_roles_meta_volume }}
infinito build roles_list --no-signal --alarm-timeout 0 -o {{ mig_roles_meta_list }}
async: "{{ (3600 if ASYNC_ENABLED else omit) | default(omit) }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
async: "{{ (3600 if ASYNC_ENABLED | bool else omit) | default(omit) }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
register: mig_build_job
- name: Fail if MIG build job did not start

View File

@ -10,5 +10,5 @@
("is already a member of" not in (
(add_admin_to_group.stderr | default('')) ~ (add_admin_to_group.stdout | default(''))
))
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"

View File

@ -18,5 +18,5 @@
( ((syscfg_shell.stdout | default('')) ~ (syscfg_shell.stderr | default('')))
is search(' set to ') )
failed_when: not ASYNC_ENABLED and syscfg_shell.rc != 0
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"

View File

@ -10,5 +10,5 @@
((disable_result.stdout | default('') ~ disable_result.stderr | default('')) is search('disabled'))
and (((disable_result.stdout | default('') ~ disable_result.stderr | default('')) is not search('already disabled')))
when: not (plugin_value.enabled | bool)
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"

View File

@ -18,8 +18,8 @@
is not search('already disabled'))
)
failed_when: false
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
- name: install {{ plugin_key }} nextcloud plugin
command: "{{ nextcloud_docker_exec_occ }} app:install {{ plugin_key }}"

View File

@ -32,8 +32,8 @@
not ASYNC_ENABLED and
(config_set_shell.stdout | default('')) is search(' set to ')
failed_when: not ASYNC_ENABLED and config_set_shell.rc != 0
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
- name: Check if {{nextcloud_control_node_plugin_tasks_directory}}{{ plugin_key }}.yml exists
stat: