From e0538c81f3ec0468971a7134a6913f4cb70f7ef6 Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Mon, 9 Jan 2023 18:24:30 +0100 Subject: [PATCH] rabbitmq: Use assert on checks for readability assert will also fail when we're not meeting the conditions, makes clear what we're actually testing, and isn't listed as a skipped task when the condition is ok. Change-Id: I4c919b523dde2602c81179ab3d28b913650b4c9f --- ansible/roles/rabbitmq/tasks/precheck.yml | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ansible/roles/rabbitmq/tasks/precheck.yml b/ansible/roles/rabbitmq/tasks/precheck.yml index 8743f5c8aa..9eed665405 100644 --- a/ansible/roles/rabbitmq/tasks/precheck.yml +++ b/ansible/roles/rabbitmq/tasks/precheck.yml @@ -76,30 +76,30 @@ - not item.1 is match('^'+('api' | kolla_address(item.0.item))+'\\b') - name: Check if TLS certificate exists for RabbitMQ + assert: + that: cert | length > 0 + fail_msg: No TLS certificate provided for RabbitMQ. vars: cert: "{{ query('first_found', paths, errors='ignore') }}" paths: - "{{ kolla_certificates_dir }}/{{ inventory_hostname }}/rabbitmq-cert.pem" - "{{ kolla_certificates_dir }}/{{ inventory_hostname }}-cert.pem" - "{{ kolla_certificates_dir }}/rabbitmq-cert.pem" - fail: - msg: No TLS certificate provided for RabbitMQ. when: - rabbitmq_enable_tls | bool - - cert | length == 0 - name: Check if TLS key exists for RabbitMQ + assert: + that: key | length > 0 + fail_msg: No TLS key provided for RabbitMQ. vars: key: "{{ query('first_found', paths, errors='ignore') }}" paths: - "{{ kolla_certificates_dir }}/{{ inventory_hostname }}/rabbitmq-key.pem" - "{{ kolla_certificates_dir }}/{{ inventory_hostname }}-key.pem" - "{{ kolla_certificates_dir }}/rabbitmq-key.pem" - fail: - msg: No TLS key provided for RabbitMQ. when: - rabbitmq_enable_tls | bool - - key | length == 0 - name: Checking free port for outward RabbitMQ wait_for: @@ -166,29 +166,29 @@ - not item.1 is match('^'+('api' | kolla_address(item.0.item))+'\\b') - name: Check if TLS certificate exists for outward RabbitMQ + assert: + that: cert | length > 0 + fail_msg: No TLS certificate provided for outward RabbitMQ. vars: cert: "{{ query('first_found', paths, errors='ignore') }}" paths: - "{{ kolla_certificates_dir }}/{{ inventory_hostname }}/outward_rabbitmq-cert.pem" - "{{ kolla_certificates_dir }}/{{ inventory_hostname }}-cert.pem" - "{{ kolla_certificates_dir }}/outward_rabbitmq-cert.pem" - fail: - msg: No TLS certificate provided for outward RabbitMQ. when: - enable_outward_rabbitmq | bool - rabbitmq_enable_tls | bool - - cert | length == 0 - name: Check if TLS key exists for outward RabbitMQ + assert: + that: key | length > 0 + msg: No TLS key provided for outward RabbitMQ. vars: key: "{{ query('first_found', paths, errors='ignore') }}" paths: - "{{ kolla_certificates_dir }}/{{ inventory_hostname }}/outward_rabbitmq-key.pem" - "{{ kolla_certificates_dir }}/{{ inventory_hostname }}-key.pem" - "{{ kolla_certificates_dir }}/outward_rabbitmq-key.pem" - fail: - msg: No TLS key provided for outward RabbitMQ. when: - enable_outward_rabbitmq | bool - rabbitmq_enable_tls | bool - - key | length == 0