From 8e81840317e9cad9ce25a3f14299b4d41a0db7c7 Mon Sep 17 00:00:00 2001 From: Romain Pelisse Date: Mon, 9 Oct 2023 14:40:08 +0200 Subject: [PATCH] DONOTMERGE --- .../tasks/validation/service.yml | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/roles/amq_streams_common/tasks/validation/service.yml b/roles/amq_streams_common/tasks/validation/service.yml index 187407d..84abe5b 100644 --- a/roles/amq_streams_common/tasks/validation/service.yml +++ b/roles/amq_streams_common/tasks/validation/service.yml @@ -8,14 +8,19 @@ - name: Populate service facts ansible.builtin.service_facts: -- name: Check if service is started - ansible.builtin.assert: - that: - - ansible_facts is defined - - ansible_facts.services is defined - - ansible_facts.services["{{ service_name }}.service"] is defined - - ansible_facts.services["{{ service_name }}.service"]['state'] is defined - - ansible_facts.services["{{ service_name }}.service"]['state'] == 'running' - - ansible_facts.services["{{ service_name }}.service"]['status'] == 'enabled' - quiet: true - fail_msg: "Service is not started." +- name: "Check service status" + block: + - name: Check if service is started + ansible.builtin.assert: + that: + - ansible_facts is defined + - ansible_facts.services is defined + - ansible_facts.services["{{ service_name }}.service"] is defined + - ansible_facts.services["{{ service_name }}.service"]['state'] is defined + - ansible_facts.services["{{ service_name }}.service"]['state'] == 'running' + - ansible_facts.services["{{ service_name }}.service"]['status'] == 'enabled' + quiet: true + fail_msg: "Service is not started." + rescue: + - name: "Display service status" + ansible.builtin.command: systemctl status "{{ service_name }}"