From f9921de0f066a39781be498dd96ab4ad82bbc3b5 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 6 Feb 2025 11:20:14 +0100 Subject: [PATCH] refs #8025 send test email to AWX user email if defined, facts improved and renamed to debug --- playbooks/debug.yml | 20 ++++++++++++++++++++ playbooks/facts.yml | 10 ---------- roles/debian/defaults/main.yaml | 1 + roles/debian/tasks/relayhost.yml | 8 ++++++-- 4 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 playbooks/debug.yml delete mode 100644 playbooks/facts.yml diff --git a/playbooks/debug.yml b/playbooks/debug.yml new file mode 100644 index 0000000..8f844cd --- /dev/null +++ b/playbooks/debug.yml @@ -0,0 +1,20 @@ +- name: Gather facts from host and print variables + hosts: all + gather_facts: yes + tasks: + + - name: Print ansible facts + tags: facts + debug: + var: ansible_facts + + - name: Print all variables + tags: vars + debug: + var: vars + + - name: Print variable value + tags: var + when: var_name is defined + debug: + msg: "{{ var_name }}: {{ lookup('vars', var_name, default='undefined') }}" diff --git a/playbooks/facts.yml b/playbooks/facts.yml deleted file mode 100644 index d0b3c0d..0000000 --- a/playbooks/facts.yml +++ /dev/null @@ -1,10 +0,0 @@ -- name: Gather facts from host and print all variables - hosts: all - gather_facts: yes - tasks: - - name: Print all variables - debug: - var: vars - - name: Print variable value - debug: - msg: "Variable: {{ ansible_fqdn }}" diff --git a/roles/debian/defaults/main.yaml b/roles/debian/defaults/main.yaml index a750a38..740257e 100644 --- a/roles/debian/defaults/main.yaml +++ b/roles/debian/defaults/main.yaml @@ -1,6 +1,7 @@ vn_env: lab vn_first_time: false vn_witness_checked: false +send_test_email: true deb_packages: - https://apt.verdnatura.es/pool/main/v/vn-host/vn-apt-source_3.0.1_all.deb - https://apt.verdnatura.es/pool/main/v/vn-host/vn-host_3.0.1_all.deb diff --git a/roles/debian/tasks/relayhost.yml b/roles/debian/tasks/relayhost.yml index f912812..1aeaebd 100644 --- a/roles/debian/tasks/relayhost.yml +++ b/roles/debian/tasks/relayhost.yml @@ -27,7 +27,11 @@ - name: Force execution of handlers immediately meta: flush_handlers - name: Sending mail to verify relay host configuration works + when: > + exim_config.changed + and send_test_email + and awx_user_email is defined + and awx_user_email | length > 0 shell: > sleep 2; echo "If you see this message, relayhost on {{ ansible_fqdn }} has been configured correctly." \ - | mailx -s "Relayhost test for {{ ansible_fqdn }}" "{{ sysadmin_mail }}" - when: exim_config.changed + | mailx -s "Relayhost test for {{ ansible_fqdn }}" "{{ awx_user_email }}"