From 1db187dcb911d76fb636c2455be68869c854a0cb Mon Sep 17 00:00:00 2001 From: Romain Pelisse Date: Tue, 3 Oct 2023 13:06:51 +0200 Subject: [PATCH] molecule cleanup (reduce code dupl) --- molecule/all_auth/molecule.yml | 2 +- molecule/all_cluster/molecule.yml | 2 +- molecule/all_cluster/prepare.yml | 10 ----- molecule/connect/molecule.yml | 2 +- molecule/connect/prepare.yml | 10 ----- molecule/default/molecule.yml | 2 +- molecule/default/prepare.yml | 10 ----- molecule/{all_auth => }/prepare.yml | 0 .../prepare.yml => prepare_ssl.yml} | 0 molecule/ssl_auth_sasl/molecule.yml | 2 +- molecule/ssl_auth_sasl/prepare.yml | 42 ------------------- molecule/ssl_no_auth/molecule.yml | 2 +- roles/amq_streams_common/tasks/prometheus.yml | 26 ++++++++++++ 13 files changed, 32 insertions(+), 78 deletions(-) delete mode 100644 molecule/all_cluster/prepare.yml delete mode 100644 molecule/connect/prepare.yml delete mode 100644 molecule/default/prepare.yml rename molecule/{all_auth => }/prepare.yml (100%) rename molecule/{ssl_no_auth/prepare.yml => prepare_ssl.yml} (100%) delete mode 100644 molecule/ssl_auth_sasl/prepare.yml create mode 100644 roles/amq_streams_common/tasks/prometheus.yml diff --git a/molecule/all_auth/molecule.yml b/molecule/all_auth/molecule.yml index 2fa4982..29aab5a 100644 --- a/molecule/all_auth/molecule.yml +++ b/molecule/all_auth/molecule.yml @@ -18,7 +18,7 @@ provisioner: ssh_connection: pipelining: false playbooks: - prepare: prepare.yml + prepare: ../prepare.yml converge: converge.yml verify: verify.yml inventory: diff --git a/molecule/all_cluster/molecule.yml b/molecule/all_cluster/molecule.yml index 64eb5cd..2ddeba3 100644 --- a/molecule/all_cluster/molecule.yml +++ b/molecule/all_cluster/molecule.yml @@ -18,7 +18,7 @@ provisioner: ssh_connection: pipelining: false playbooks: - prepare: prepare.yml + prepare: ../prepare.yml converge: converge.yml verify: verify.yml inventory: diff --git a/molecule/all_cluster/prepare.yml b/molecule/all_cluster/prepare.yml deleted file mode 100644 index 0edc37a..0000000 --- a/molecule/all_cluster/prepare.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Prepare - hosts: all - tasks: - - - name: "Ensure required packages are installed." - ansible.builtin.yum: - name: - - sudo - state: present diff --git a/molecule/connect/molecule.yml b/molecule/connect/molecule.yml index 2fa4982..29aab5a 100644 --- a/molecule/connect/molecule.yml +++ b/molecule/connect/molecule.yml @@ -18,7 +18,7 @@ provisioner: ssh_connection: pipelining: false playbooks: - prepare: prepare.yml + prepare: ../prepare.yml converge: converge.yml verify: verify.yml inventory: diff --git a/molecule/connect/prepare.yml b/molecule/connect/prepare.yml deleted file mode 100644 index 0edc37a..0000000 --- a/molecule/connect/prepare.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Prepare - hosts: all - tasks: - - - name: "Ensure required packages are installed." - ansible.builtin.yum: - name: - - sudo - state: present diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 424e162..3cd07ca 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -18,7 +18,7 @@ provisioner: ssh_connection: pipelining: false playbooks: - prepare: prepare.yml + prepare: ../prepare.yml converge: converge.yml verify: verify.yml inventory: diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml deleted file mode 100644 index 0edc37a..0000000 --- a/molecule/default/prepare.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Prepare - hosts: all - tasks: - - - name: "Ensure required packages are installed." - ansible.builtin.yum: - name: - - sudo - state: present diff --git a/molecule/all_auth/prepare.yml b/molecule/prepare.yml similarity index 100% rename from molecule/all_auth/prepare.yml rename to molecule/prepare.yml diff --git a/molecule/ssl_no_auth/prepare.yml b/molecule/prepare_ssl.yml similarity index 100% rename from molecule/ssl_no_auth/prepare.yml rename to molecule/prepare_ssl.yml diff --git a/molecule/ssl_auth_sasl/molecule.yml b/molecule/ssl_auth_sasl/molecule.yml index 424e162..7752c21 100644 --- a/molecule/ssl_auth_sasl/molecule.yml +++ b/molecule/ssl_auth_sasl/molecule.yml @@ -18,7 +18,7 @@ provisioner: ssh_connection: pipelining: false playbooks: - prepare: prepare.yml + prepare: ../prepare_ssl.yml converge: converge.yml verify: verify.yml inventory: diff --git a/molecule/ssl_auth_sasl/prepare.yml b/molecule/ssl_auth_sasl/prepare.yml deleted file mode 100644 index fcbf82d..0000000 --- a/molecule/ssl_auth_sasl/prepare.yml +++ /dev/null @@ -1,42 +0,0 @@ ---- -- name: Prepare - hosts: all -# collections: -# - community.general.java_keystore -# - community.crypto - tasks: - - - name: "Ensure required packages are installed." - ansible.builtin.yum: - name: - - sudo - - java-17-openjdk-headless - - openssl - state: present - - - ansible.builtin.copy: - src: generate_keys_and_certs.sh - dest: /tmp/ - owner: root - group: root - mode: "0077" - - - name: "Generate required SSL artifacts." - ansible.builtin.command: "/tmp/generate_keys_and_certs.sh" - register: output - - - ansible.builtin.debug: - var: output - -# TODO: use Ansible crypto and jks collections to replace above script -# - name: Generate an OpenSSH keypair with the default values (4096 bits, rsa) -# community.crypto.openssh_keypair: -# path: /tmp/id_ssh_rsa -# -# - name: Create a keystore for the given certificate/private key pair (inline) -# community.general.java_keystore: -# name: example -# certificate: /etc/ssl/certs/ca-bundle.crt -# private_key: /tmp/id_ssh_rsa -# password: changeit -# dest: /etc/security/keystore.jks diff --git a/molecule/ssl_no_auth/molecule.yml b/molecule/ssl_no_auth/molecule.yml index 424e162..3cd07ca 100644 --- a/molecule/ssl_no_auth/molecule.yml +++ b/molecule/ssl_no_auth/molecule.yml @@ -18,7 +18,7 @@ provisioner: ssh_connection: pipelining: false playbooks: - prepare: prepare.yml + prepare: ../prepare.yml converge: converge.yml verify: verify.yml inventory: diff --git a/roles/amq_streams_common/tasks/prometheus.yml b/roles/amq_streams_common/tasks/prometheus.yml new file mode 100644 index 0000000..27d7e6d --- /dev/null +++ b/roles/amq_streams_common/tasks/prometheus.yml @@ -0,0 +1,26 @@ +--- +- name: "Ensure required parameters for Prometheus are provided." + ansible.builtin.assert: + that: + - amq_streams_common_prometheus_config_file is defined and amq_streams_common_prometheus_config_file | length > 0 + - amq_streams_common_prometheus_config_file_template is defined and amq_streams_common_prometheus_config_file_template | length > 0 + quiet: True + +- name: "Ensure directory {{ amq_streams_common_prometheus_metrics_config_home }} exits." + ansible.builtin.file: + path: "{{ amq_streams_common_prometheus_metrics_config_home }}" + state: directory + +- name: "Deploy Prometheus metrics file (src: {{ amq_streams_common_prometheus_config_file_template }} to dest: {{ amq_streams_common_prometheus_metrics_config_home }}{{ amq_streams_common_prometheus_config_file }}" + ansible.builtin.template: + src: "{{ amq_streams_common_prometheus_config_file_template }}" + dest: "{{ amq_streams_common_prometheus_metrics_config_home }}{{ amq_streams_common_prometheus_config_file }}" + owner: "{{ amq_streams_common_prometheus_user | default(omit) }}" + group: "{{ amq_streams_common_prometheus_group | default(omit) }}" + mode: 0644 + +- name: "Add prometheus dependency (if enabled: {{ amq_streams_common_prometheus_enabled }})." + ansible.builtin.set_fact: + amq_streams_common_dependencies: "{{ [amq_streams_common_dependencies + ['{{ amq_streams_common_prometheus_package_name }}']] | flatten }}" + when: + - amq_streams_common_prometheus_install_rpm is defined and amq_streams_common_prometheus_install_rpm