From 95aaaf1337f32b1cccf25250e42a9dcbb7b77000 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Tue, 28 Feb 2023 18:15:01 +0100 Subject: [PATCH] Allow to provide custom handler names Introduce variables that allow to customize handler names that are being used. This is especially useful when role is included multiple times within same playbook. Depends-On: https://review.opendev.org/c/openstack/openstack-ansible-rabbitmq_server/+/876436 Needed-By: https://review.opendev.org/c/openstack/openstack-ansible/+/871189/ Change-Id: I66ad04a5dbbce29c052895649792fa8a49e40a57 --- defaults/main.yml | 5 +++++ handlers/main.yml | 9 +++++---- .../notes/pki_handler_variables-6e72209f9cbc4cf5.yaml | 8 ++++++++ tasks/main_certs.yml | 2 +- tasks/standalone/create_ca.yml | 4 ++-- tasks/standalone/create_cert.yml | 2 +- 6 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 releasenotes/notes/pki_handler_variables-6e72209f9cbc4cf5.yaml diff --git a/defaults/main.yml b/defaults/main.yml index 29c7cb3..2a5e1ea 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -150,3 +150,8 @@ pki_search_install_certificates_pattern: "pki_install_certificates_" # method used to create the certificates pki_method: standalone + +# Handlers naming +pki_handler_ca_changed: "ca cert changed" +pki_handler_cert_changed: "cert changed" +pki_handler_cert_installed: "cert installed" diff --git a/handlers/main.yml b/handlers/main.yml index bab6834..bbd03dd 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,3 +1,4 @@ +--- # Copyright 2021, BBC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,16 +14,16 @@ # limitations under the License. # when the created CA certificates are changed -- name: ca cert changed +- name: "{{ pki_handler_ca_changed }}" meta: noop when: false # when the created server certificates are changed -- name: cert changed +- name: "{{ pki_handler_cert_changed }}" meta: noop when: false # when a certificate is installed onto a server -- name: cert installed +- name: "{{ pki_handler_cert_installed }}" meta: noop - when: false \ No newline at end of file + when: false diff --git a/releasenotes/notes/pki_handler_variables-6e72209f9cbc4cf5.yaml b/releasenotes/notes/pki_handler_variables-6e72209f9cbc4cf5.yaml new file mode 100644 index 0000000..710abc9 --- /dev/null +++ b/releasenotes/notes/pki_handler_variables-6e72209f9cbc4cf5.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Added variables ``pki_handler_ca_changed``, ``pki_handler_cert_changed`` + and ``pki_handler_cert_installed`` that control name of meta handlers which + role triggers when included. This might be useful if multiple roles that + leverage the pki role are inlcuded withing same playbook and you want to + have better control over handler execution. diff --git a/tasks/main_certs.yml b/tasks/main_certs.yml index cfd43c8..2f78b0c 100644 --- a/tasks/main_certs.yml +++ b/tasks/main_certs.yml @@ -78,4 +78,4 @@ mode: "{{ install.item.mode | default('0644') }}" ignore_errors: "{{ ansible_check_mode }}" notify: - - cert installed + - "{{ pki_handler_cert_installed }}" diff --git a/tasks/standalone/create_ca.yml b/tasks/standalone/create_ca.yml index 44bd16d..c1620e1 100644 --- a/tasks/standalone/create_ca.yml +++ b/tasks/standalone/create_ca.yml @@ -109,7 +109,7 @@ - ca.provider == 'selfsigned' - ca_csr is changed notify: - - ca cert changed + - "{{ pki_handler_ca_changed }}" - name: Sign the intermediate CA CSR for {{ ca.name }} vars: @@ -127,7 +127,7 @@ - ca.provider == 'ownca' - ca_csr is changed notify: - - ca cert changed + - "{{ pki_handler_ca_changed }}" - name: Symlink the certificate name to the most recently generated file: diff --git a/tasks/standalone/create_cert.yml b/tasks/standalone/create_cert.yml index 876edaf..b72d346 100644 --- a/tasks/standalone/create_cert.yml +++ b/tasks/standalone/create_cert.yml @@ -65,7 +65,7 @@ - cert.provider == 'ownca' - cert_csr is changed notify: - - cert changed + - "{{ pki_handler_cert_changed }}" ignore_errors: "{{ ansible_check_mode }}" - name: Get certificate info for {{ cert.name }}