From f744747cef0caba0b30b2819491d042156786b24 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 13 Jul 2025 02:57:03 +0200 Subject: [PATCH] Added some variable debugging tools --- tasks/utils/debug/README.md | 35 +++++++++++++++++++ tasks/utils/debug/docker-compose.yml | 50 ++++++++++++++++++++++++++++ tasks/utils/debug/main.yml | 35 +++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 tasks/utils/debug/README.md create mode 100644 tasks/utils/debug/docker-compose.yml create mode 100644 tasks/utils/debug/main.yml diff --git a/tasks/utils/debug/README.md b/tasks/utils/debug/README.md new file mode 100644 index 00000000..a391a05f --- /dev/null +++ b/tasks/utils/debug/README.md @@ -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. \ No newline at end of file diff --git a/tasks/utils/debug/docker-compose.yml b/tasks/utils/debug/docker-compose.yml new file mode 100644 index 00000000..9a9da175 --- /dev/null +++ b/tasks/utils/debug/docker-compose.yml @@ -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. diff --git a/tasks/utils/debug/main.yml b/tasks/utils/debug/main.yml new file mode 100644 index 00000000..970e6944 --- /dev/null +++ b/tasks/utils/debug/main.yml @@ -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