Added some variable debugging tools

This commit is contained in:
Kevin Veen-Birkenbach 2025-07-13 02:57:03 +02:00
parent bff6f8b5a0
commit f744747cef
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
3 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,35 @@
# Debug Variables Task Include
This task file (`tasks/utils/debug/main.yml`) outputs key variables for troubleshooting Ansible roles and playbooks.
## Purpose
Use this file to quickly debug and inspect variables such as `application_id`, `applications`, `ports`, and more. It helps identify missing or misconfigured variables during playbook runs.
## Usage
Include the debug file in any task list or role:
```yaml
- import_tasks: utils/debug/main.yml
````
or
```yaml
- include_tasks: utils/debug/main.yml
```
Optionally, enable it conditionally:
```yaml
- import_tasks: utils/debug/main.yml
when: enable_debug | default(false)
```
**Note:**
The path is relative to the directory of your task file.
---
This tool is intended for development and troubleshooting only. Remove or disable it in production runs.

View File

@ -0,0 +1,50 @@
- name: Assert all required application_id-based variables are defined
vars:
missing_keys: []
block:
- name: Check if applications[application_id] exists
set_fact:
missing_keys: "{{ missing_keys + ['applications'] }}"
when: applications.get(application_id, None) is not defined
- name: Check if applications[application_id].docker.services.database.enabled exists
set_fact:
missing_keys: "{{ missing_keys + ['applications.{}.docker.services.database.enabled'.format(application_id)] }}"
when: applications[application_id].docker.services.database is not defined
- name: Check if applications[application_id].docker.services.redis.enabled exists
set_fact:
missing_keys: "{{ missing_keys + ['applications.{}.docker.services.redis.enabled'.format(application_id)] }}"
when: applications[application_id].docker.services.redis is not defined
- name: Check if applications[application_id].images[application_id] exists
set_fact:
missing_keys: "{{ missing_keys + ['applications.{}.images.{}'.format(application_id, application_id)] }}"
when: applications[application_id].images is not defined or applications[application_id].images.get(application_id) is not defined
- name: Check if applications[application_id].features exists
set_fact:
missing_keys: "{{ missing_keys + ['applications.{}.features'.format(application_id)] }}"
when: applications[application_id].features is not defined
- name: Check if ports.localhost.oauth2_proxy[application_id] exists
set_fact:
missing_keys: "{{ missing_keys + ['ports.localhost.oauth2_proxy.{}'.format(application_id)] }}"
when: ports.localhost.oauth2_proxy.get(application_id, None) is not defined
- name: Check if ports.localhost.http[application_id] exists
set_fact:
missing_keys: "{{ missing_keys + ['ports.localhost.http.{}'.format(application_id)] }}"
when: ports.localhost.http.get(application_id, None) is not defined
- name: Check if networks.local[application_id].subnet exists (optional)
set_fact:
missing_keys: "{{ missing_keys + ['networks.local.{}.subnet'.format(application_id)] }}"
when: networks.local.get(application_id, None) is not defined or networks.local[application_id].get('subnet', None) is not defined
- name: Fail if any required keys are missing
debug:
msg: |
The following variables/keys for application_id {{ application_id }} are not defined or not accessible:
{{ missing_keys | join('\n- ') }}
Please define them in your group_vars, host_vars, or inventory.

View File

@ -0,0 +1,35 @@
- name: Show application_id
debug:
var: application_id
- name: Show applications dict
debug:
var: applications
- name: Show ports
debug:
var: ports
- name: Show networks
debug:
var: networks
- name: Show database_type
debug:
var: database_type
- name: Show database_host
debug:
var: database_host
- name: Show docker_compose
debug:
var: docker_compose
- name: Show container_port
debug:
var: container_port
- name: Show container_healthcheck
debug:
var: container_healthcheck