Refactor task includes and update variable handling for Ansible 2.20 migration

This commit updates multiple roles to ensure compatibility with Ansible 2.20.
Several include paths and task-loading mechanisms required adjustments,
as Ansible 2.20 applies stricter evaluation rules for complex Jinja expressions
and no longer resolves certain relative include paths the way Ansible 2.18 did.

Key changes:
- Replaced legacy once_finalize.yml and once_flag.yml with the new structure
  under tasks/utils/once/finalize.yml and tasks/utils/once/flag.yml.
- Updated all include_tasks statements to use 'path_join' with playbook_dir,
  ensuring deterministic and absolute file resolution across roles.
- Fixed all network helper includes by converting direct relative paths such as
  'roles/docker-compose/tasks/utils/network.yml' to proper Jinja-evaluated paths.
- Normalized MATOMO_* variable names for consistency with the updated variable
  scope behavior in Ansible 2.20.
- Removed deprecated patterns that were implicitly supported in Ansible 2.18
  but break under the more strict variable and path resolution model in 2.20.

These changes are part of the full migration step required to ensure the
infinito-nexus roles remain stable, deterministic, and forward-compatible with
Ansible 2.20.

Details of the discussion and reasoning can be found in this conversation:
https://chatgpt.com/share/69300a8d-24d4-800f-bec0-e895a695618a
This commit is contained in:
2025-12-03 11:02:34 +01:00
parent a6ed047765
commit 716ebef33b
169 changed files with 348 additions and 399 deletions

View File

@@ -1,9 +1,11 @@
# Required to be set on the top to prevent infinite recursions appearing in roles/sys-front-inj-all/tasks/01_dependencies.yml
- include_tasks: utils/once_flag.yml
- include_tasks: utils/once/flag.yml
- name: "load docker, db and proxy for {{ application_id }}"
include_role:
name: sys-stk-full-stateful
vars:
docker_compose_flush_handlers: false
- name: "Patch Matomo config.ini.php"
include_tasks: 02_configuration.yml
@@ -20,7 +22,7 @@
body:
module: API
method: SitesManager.setGlobalExcludedIps
excludedIps: "{{ matomo_excluded_ips | join(',') }}"
excludedIps: "{{ MATOMO_EXCLUDED_IPS | join(',') }}"
format: json
token_auth: "{{ matomo_auth_token }}"
return_content: yes
@@ -44,4 +46,4 @@
return_content: yes
status_code: 200
- include_tasks: utils/compose_up.yml
- include_tasks: "{{ [playbook_dir, 'roles/docker-compose/tasks/utils/up.yml' ] | path_join }}"

View File

@@ -1,25 +1,30 @@
- name: Update DB host
command: >
docker exec --user root {{ matomo_name }}
sed -i "s/^host *=.*/host = {{ database_host }}/" {{ matomo_config }}
docker exec --user root {{ MATOMO_NAME }}
sed -i "s/^host *=.*/host = {{ database_host }}/" {{ MATOMO_CONFIG }}
notify: docker compose up
- name: Update DB name
command: >
docker exec --user root {{ matomo_name }}
sed -i "s/^dbname *=.*/dbname = {{ database_name }}/" {{ matomo_config }}
docker exec --user root {{ MATOMO_NAME }}
sed -i "s/^dbname *=.*/dbname = {{ database_name }}/" {{ MATOMO_CONFIG }}
notify: docker compose up
- name: Update DB user
command: >
docker exec --user root {{ matomo_name }}
sed -i "s/^username *=.*/username = {{ database_username }}/" {{ matomo_config }}
docker exec --user root {{ MATOMO_NAME }}
sed -i "s/^username *=.*/username = {{ database_username }}/" {{ MATOMO_CONFIG }}
notify: docker compose up
- name: Update DB password
command: >
docker exec --user root {{ matomo_name }}
sed -i "s/^password *=.*/password = {{ database_password }}/" {{ matomo_config }}
docker exec --user root {{ MATOMO_NAME }}
sed -i "s/^password *=.*/password = {{ database_password }}/" {{ MATOMO_CONFIG }}
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
notify: docker compose up
- name: Update trusted host
command: >
docker exec --user root {{ matomo_name }}
sed -i "s|^trusted_hosts\[\].*|trusted_hosts[] = \"{{ domain }}\"|" {{ matomo_config }}
docker exec --user root {{ MATOMO_NAME }}
sed -i "s|^trusted_hosts\[\].*|trusted_hosts[] = \"{{ domain }}\"|" {{ MATOMO_CONFIG }}
notify: docker compose up