mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-15 08:30:46 +02:00
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:
parent
597e9d5222
commit
c729edb525
@ -65,9 +65,9 @@ DOCKER_RESTART_POLICY: "unless-stopped"
|
|||||||
DOCKER_VARS_FILE: "{{ playbook_dir }}/roles/docker-compose/vars/docker-compose.yml"
|
DOCKER_VARS_FILE: "{{ playbook_dir }}/roles/docker-compose/vars/docker-compose.yml"
|
||||||
|
|
||||||
# Asyn Confitguration
|
# Asyn Confitguration
|
||||||
ASYNC_ENABLED: "{{ not MODE_DEBUG | bool}}" # Activate async, deactivated for debugging
|
ASYNC_ENABLED: "{{ not MODE_DEBUG | bool }}" # Activate async, deactivated for debugging
|
||||||
ASYNC_TIME: "{{ 300 if ASYNC_ENABLED else omit }}" # Run for mnax 5min
|
ASYNC_TIME: "{{ 300 if ASYNC_ENABLED | bool else omit }}" # Run for mnax 5min
|
||||||
ASYNC_POLL: "{{ 0 if ASYNC_ENABLED else 10 }}" # Don't wait for task
|
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
|
# default value if not set via CLI (-e) or in playbook vars
|
||||||
allowed_applications: []
|
allowed_applications: []
|
||||||
|
@ -23,4 +23,5 @@ nginx:
|
|||||||
cache:
|
cache:
|
||||||
general: "/tmp/cache_nginx_general/" # Directory which nginx uses to cache general data
|
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
|
image: "/tmp/cache_nginx_image/" # Directory which nginx uses to cache images
|
||||||
user: "http" # Default nginx user in ArchLinux
|
user: "http" # Default nginx user in ArchLinux
|
||||||
|
|
@ -9,4 +9,5 @@
|
|||||||
purge_everything: true
|
purge_everything: true
|
||||||
body_format: json
|
body_format: json
|
||||||
return_content: yes
|
return_content: yes
|
||||||
register: cf_purge
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
Content-Type: "application/json"
|
Content-Type: "application/json"
|
||||||
return_content: yes
|
return_content: yes
|
||||||
register: cf_dev_mode_current
|
register: cf_dev_mode_current
|
||||||
|
when: ASYNC_ENABLED | bool
|
||||||
|
|
||||||
- name: "Enable Cloudflare Development Mode"
|
- name: "Enable Cloudflare Development Mode"
|
||||||
ansible.builtin.uri:
|
ansible.builtin.uri:
|
||||||
@ -28,5 +29,8 @@
|
|||||||
return_content: yes
|
return_content: yes
|
||||||
register: cf_dev_mode_enable
|
register: cf_dev_mode_enable
|
||||||
changed_when: >
|
changed_when: >
|
||||||
|
ASYNC_ENABLED | bool and
|
||||||
cf_dev_mode_current.json.result.value is defined and
|
cf_dev_mode_current.json.result.value is defined and
|
||||||
cf_dev_mode_current.json.result.value != 'on'
|
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 }}"
|
||||||
|
@ -47,9 +47,12 @@
|
|||||||
mode: '0755'
|
mode: '0755'
|
||||||
loop: >
|
loop: >
|
||||||
{{ nginx.directories.data.values() | list }}
|
{{ 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"
|
- name: "Include tasks to create cache directories"
|
||||||
include_tasks: 03_cache_directories.yml
|
include_tasks: 03_cache_directories.yml
|
||||||
|
when: run_once_nginx_reverse_proxy is not defined
|
||||||
|
|
||||||
- name: create nginx config file
|
- name: create nginx config file
|
||||||
template:
|
template:
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
state: absent
|
state: absent
|
||||||
when:
|
when:
|
||||||
- MODE_CLEANUP | bool
|
- MODE_CLEANUP | bool
|
||||||
- run_once_nginx_reverse_proxy is not defined
|
|
||||||
loop: "{{ nginx.directories.cache | dict2items }}"
|
loop: "{{ nginx.directories.cache | dict2items }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.key }}"
|
label: "{{ item.key }}"
|
||||||
@ -18,13 +17,12 @@
|
|||||||
owner: "{{ nginx.user }}"
|
owner: "{{ nginx.user }}"
|
||||||
group: "{{ nginx.user }}"
|
group: "{{ nginx.user }}"
|
||||||
mode: '0700'
|
mode: '0700'
|
||||||
|
|
||||||
when: run_once_nginx_reverse_proxy is not defined
|
|
||||||
loop: "{{ nginx.directories.cache | dict2items }}"
|
loop: "{{ nginx.directories.cache | dict2items }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.key }}"
|
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
|
- name: run the nginx_reverse_proxy tasks once
|
||||||
set_fact:
|
set_fact:
|
||||||
run_once_nginx_reverse_proxy: true
|
run_once_nginx_reverse_proxy: true
|
||||||
when: run_once_nginx_reverse_proxy is not defined
|
|
@ -19,4 +19,6 @@
|
|||||||
state: present
|
state: present
|
||||||
loop: "{{ base_sld_domains | product(caa_entries) | list }}"
|
loop: "{{ base_sld_domains | product(caa_entries) | list }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.0 }} → {{ item.1.tag }}"
|
label: "{{ item.0 }} → {{ item.1.tag }}"
|
||||||
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
@ -18,8 +18,8 @@
|
|||||||
uidNumber: "{{ item.value.uid | int }}"
|
uidNumber: "{{ item.value.uid | int }}"
|
||||||
gidNumber: "{{ item.value.gid | int }}"
|
gidNumber: "{{ item.value.gid | int }}"
|
||||||
state: present # ↳ creates but never updates
|
state: present # ↳ creates but never updates
|
||||||
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
||||||
loop: "{{ users | dict2items }}"
|
loop: "{{ users | dict2items }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.key }}"
|
label: "{{ item.key }}"
|
||||||
@ -37,8 +37,8 @@
|
|||||||
objectClass: "{{ ldap.user.objects.structural }}"
|
objectClass: "{{ ldap.user.objects.structural }}"
|
||||||
mail: "{{ item.value.email }}"
|
mail: "{{ item.value.email }}"
|
||||||
state: exact
|
state: exact
|
||||||
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
||||||
loop: "{{ users | dict2items }}"
|
loop: "{{ users | dict2items }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.key }}"
|
label: "{{ item.key }}"
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
attributes:
|
attributes:
|
||||||
objectClass: "{{ missing_auxiliary }}"
|
objectClass: "{{ missing_auxiliary }}"
|
||||||
state: present
|
state: present
|
||||||
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
||||||
loop: "{{ ldap_users_with_classes.results }}"
|
loop: "{{ ldap_users_with_classes.results }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.dn }}"
|
label: "{{ item.dn }}"
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
proxied: false
|
proxied: false
|
||||||
ttl: 1
|
ttl: 1
|
||||||
state: present
|
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"
|
- name: "Set CNAME record for autoconfig"
|
||||||
community.general.cloudflare_dns:
|
community.general.cloudflare_dns:
|
||||||
@ -25,6 +27,8 @@
|
|||||||
proxied: false
|
proxied: false
|
||||||
ttl: 1
|
ttl: 1
|
||||||
state: present
|
state: present
|
||||||
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
||||||
|
|
||||||
- name: "Set MX record"
|
- name: "Set MX record"
|
||||||
community.general.cloudflare_dns:
|
community.general.cloudflare_dns:
|
||||||
@ -36,6 +40,8 @@
|
|||||||
priority: 10
|
priority: 10
|
||||||
ttl: 1
|
ttl: 1
|
||||||
state: present
|
state: present
|
||||||
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
||||||
|
|
||||||
- name: "Set SRV records"
|
- name: "Set SRV records"
|
||||||
community.general.cloudflare_dns:
|
community.general.cloudflare_dns:
|
||||||
@ -55,6 +61,8 @@
|
|||||||
#register: srv_result
|
#register: srv_result
|
||||||
#failed_when: srv_result.rc != 0 and ("An identical record already exists" not in srv_result.stdout)
|
#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)
|
#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"
|
- name: "Set SPF TXT record"
|
||||||
community.general.cloudflare_dns:
|
community.general.cloudflare_dns:
|
||||||
@ -65,6 +73,8 @@
|
|||||||
value: "v=spf1 mx a:{{ domain }} ~all"
|
value: "v=spf1 mx a:{{ domain }} ~all"
|
||||||
ttl: 1
|
ttl: 1
|
||||||
state: present
|
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"
|
- name: "Set DMARC TXT record"
|
||||||
community.general.cloudflare_dns:
|
community.general.cloudflare_dns:
|
||||||
@ -75,6 +85,8 @@
|
|||||||
value: "v=DMARC1; p=reject; ruf=mailto:{{ mailu_dmarc_ruf }}; adkim=s; aspf=s"
|
value: "v=DMARC1; p=reject; ruf=mailto:{{ mailu_dmarc_ruf }}; adkim=s; aspf=s"
|
||||||
ttl: 1
|
ttl: 1
|
||||||
state: present
|
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"
|
- name: "Set DKIM TXT record"
|
||||||
community.general.cloudflare_dns:
|
community.general.cloudflare_dns:
|
||||||
@ -84,4 +96,6 @@
|
|||||||
name: "dkim._domainkey.{{ mailu_dns_zone }}"
|
name: "dkim._domainkey.{{ mailu_dns_zone }}"
|
||||||
value: "{{ mailu_dkim_public_key }}"
|
value: "{{ mailu_dkim_public_key }}"
|
||||||
ttl: 1
|
ttl: 1
|
||||||
state: present
|
state: present
|
||||||
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
@ -3,8 +3,8 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
infinito build tree --no-signal --alarm-timeout 0 -s {{ mig_roles_meta_volume }}
|
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 }}
|
infinito build roles_list --no-signal --alarm-timeout 0 -o {{ mig_roles_meta_list }}
|
||||||
async: "{{ (3600 if ASYNC_ENABLED else omit) | default(omit) }}"
|
async: "{{ (3600 if ASYNC_ENABLED | bool else omit) | default(omit) }}"
|
||||||
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
||||||
register: mig_build_job
|
register: mig_build_job
|
||||||
|
|
||||||
- name: Fail if MIG build job did not start
|
- name: Fail if MIG build job did not start
|
||||||
|
@ -10,5 +10,5 @@
|
|||||||
("is already a member of" not in (
|
("is already a member of" not in (
|
||||||
(add_admin_to_group.stderr | default('')) ~ (add_admin_to_group.stdout | default(''))
|
(add_admin_to_group.stderr | default('')) ~ (add_admin_to_group.stdout | default(''))
|
||||||
))
|
))
|
||||||
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
@ -18,5 +18,5 @@
|
|||||||
( ((syscfg_shell.stdout | default('')) ~ (syscfg_shell.stderr | default('')))
|
( ((syscfg_shell.stdout | default('')) ~ (syscfg_shell.stderr | default('')))
|
||||||
is search(' set to ') )
|
is search(' set to ') )
|
||||||
failed_when: not ASYNC_ENABLED and syscfg_shell.rc != 0
|
failed_when: not ASYNC_ENABLED and syscfg_shell.rc != 0
|
||||||
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
||||||
|
@ -10,5 +10,5 @@
|
|||||||
((disable_result.stdout | default('') ~ disable_result.stderr | default('')) is search('disabled'))
|
((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')))
|
and (((disable_result.stdout | default('') ~ disable_result.stderr | default('')) is not search('already disabled')))
|
||||||
when: not (plugin_value.enabled | bool)
|
when: not (plugin_value.enabled | bool)
|
||||||
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
is not search('already disabled'))
|
is not search('already disabled'))
|
||||||
)
|
)
|
||||||
failed_when: false
|
failed_when: false
|
||||||
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
||||||
|
|
||||||
- name: install {{ plugin_key }} nextcloud plugin
|
- name: install {{ plugin_key }} nextcloud plugin
|
||||||
command: "{{ nextcloud_docker_exec_occ }} app:install {{ plugin_key }}"
|
command: "{{ nextcloud_docker_exec_occ }} app:install {{ plugin_key }}"
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
not ASYNC_ENABLED and
|
not ASYNC_ENABLED and
|
||||||
(config_set_shell.stdout | default('')) is search(' set to ')
|
(config_set_shell.stdout | default('')) is search(' set to ')
|
||||||
failed_when: not ASYNC_ENABLED and config_set_shell.rc != 0
|
failed_when: not ASYNC_ENABLED and config_set_shell.rc != 0
|
||||||
async: "{{ ASYNC_TIME if ASYNC_ENABLED else omit }}"
|
async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}"
|
||||||
poll: "{{ ASYNC_POLL if ASYNC_ENABLED else omit }}"
|
poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}"
|
||||||
|
|
||||||
- name: Check if {{nextcloud_control_node_plugin_tasks_directory}}{{ plugin_key }}.yml exists
|
- name: Check if {{nextcloud_control_node_plugin_tasks_directory}}{{ plugin_key }}.yml exists
|
||||||
stat:
|
stat:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user