diff --git a/roles/amq_streams_broker/tasks/main.yml b/roles/amq_streams_broker/tasks/main.yml index 9f11aa9..e31213d 100644 --- a/roles/amq_streams_broker/tasks/main.yml +++ b/roles/amq_streams_broker/tasks/main.yml @@ -54,12 +54,22 @@ when: - amq_streams_zookeeper_auth_enabled is defined and amq_streams_zookeeper_auth_enabled -- name: "Wait for Zookeeper to be available - if host and port are provided." +- name: "Check and delete this" + ansible.builtin.command: systemctl status amq_streams_zookeeper + register: res + failed_when: False + changed_when: False + +- name: "Display zk server state" + ansible.builtin.debug: + var: res + +- name: "Wait for Zookeeper to be available - if enabled ({{ amq_streams_broker_zookeeper_host }}:{{ amq_streams_broker_zookeeper_port }})." ansible.builtin.wait_for: + timeout: 600 host: "{{ amq_streams_broker_zookeeper_host }}" port: "{{ amq_streams_broker_zookeeper_port }}" when: - - 0 > 1 # Disabled until find a way to test the Zookeeper cluster connection (including all the zknodes) - amq_streams_broker_zookeeper_host is defined - amq_streams_broker_zookeeper_port is defined - amq_streams_broker_zookeeper_wait is defined and amq_streams_broker_zookeeper_wait diff --git a/roles/amq_streams_common/tasks/validation/service.yml b/roles/amq_streams_common/tasks/validation/service.yml index 187407d..c12d02e 100644 --- a/roles/amq_streams_common/tasks/validation/service.yml +++ b/roles/amq_streams_common/tasks/validation/service.yml @@ -8,14 +8,43 @@ - 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: "Verify that service is started with rescue" + 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: "Check service status" + ansible.builtin.command: systemctl status "{{ service_name }}.service" + register: systemctl_result + changed_when: False + + - name: "Print result" + ansible.builtin.debug: + var: systemctl_result + + - name: "Restart service" + ansible.builtin.service: + name: "{{ service_name }}.service" + state: restarted + + - name: "Wait 30s" + ansible.builtin.wait_for: + timeout: 30 + + - name: "Check service status" + ansible.builtin.command: systemctl status "{{ service_name }}.service" + register: systemctl_result + changed_when: False + + - name: "Print result" + ansible.builtin.debug: + var: systemctl_result