From 403ebfd2c40b41e79a5ce7fc7e27afa241e3d9a4 Mon Sep 17 00:00:00 2001 From: Guido Grazioli Date: Mon, 19 Aug 2024 11:05:57 +0200 Subject: [PATCH 1/6] Add new role activemq_uninstall --- roles/activemq_uninstall/README.md | 59 ++++++++ roles/activemq_uninstall/defaults/main.yml | 30 ++++ .../meta/argument_specs.yml | 129 ++++++++++++++++++ roles/activemq_uninstall/meta/main.yml | 31 +++++ roles/activemq_uninstall/tasks/main.yml | 10 ++ roles/activemq_uninstall/tasks/systemd.yml | 36 +++++ roles/activemq_uninstall/tasks/uninstall.yml | 69 ++++++++++ roles/activemq_uninstall/vars/main.yml | 11 ++ 8 files changed, 375 insertions(+) create mode 100644 roles/activemq_uninstall/README.md create mode 100644 roles/activemq_uninstall/defaults/main.yml create mode 100644 roles/activemq_uninstall/meta/argument_specs.yml create mode 100644 roles/activemq_uninstall/meta/main.yml create mode 100644 roles/activemq_uninstall/tasks/main.yml create mode 100644 roles/activemq_uninstall/tasks/systemd.yml create mode 100644 roles/activemq_uninstall/tasks/uninstall.yml create mode 100644 roles/activemq_uninstall/vars/main.yml diff --git a/roles/activemq_uninstall/README.md b/roles/activemq_uninstall/README.md new file mode 100644 index 0000000..2134d91 --- /dev/null +++ b/roles/activemq_uninstall/README.md @@ -0,0 +1,59 @@ +activemq_uninstall +================== + +Uninstalls an activemq service that was installed by the activemq role. + + +Dependencies +------------ + +The role depends on the following collections: + +* [middleware_automation.common](https://github.com/ansible-middleware/common) +* [ansible.posix](https://github.com/ansible-collections/ansible.posix) + +To install, from the collection root directory, run: + + ansible-galaxy collections install -r requirements.yml + + + +Role Defaults +------------- + +#### Parameters specific to uninstall role + +| Variable | Description | Default | +|:---------|:------------|:--------| +|`activemq_uninstall_skip_user`| Whether to skip user/group account deletion | `false` | +|`activemq_uninstall_skip_zipfile`| Whether to skip installation zipfile deletion | `false` | +|`activemq_uninstall_skip_artemis`| Whether to skip artemis directory deletion | `false` | + + +#### Parameters as used with activemq role + +| Variable | Description | Default | +|:---------|:------------|:--------| +|`activemq_version`| Apache Artemis version | `2.34.0` | +|`activemq_archive`| Apache Artemis install archive filename | `apache-artemis-{{ activemq_version }}-bin.zip` | +|`activemq_installdir`| Apache Artemis Installation path | `{{ activemq_dest }}/apache-artemis-{{ activemq_version }}` | +|`activemq_dest`| Root installation directory | `/opt/amq` | +|`activemq_service_user`| POSIX user running the service | `amq-broker` | +|`activemq_service_group`| POSIX group running the service | `amq-broker` | +|`activemq_service_name`| systemd service unit name | `activemq` | +|`activemq_service_user_home`| Service user home directory, defaults to artemis installation directory | `{{ activemq_dest }}/apache-artemis-{{ activemq_version }}` | +|`activemq_instance_name`| Name of broker instance to deploy | `amq-broker` | +|`activemq_configure_firewalld`| Whether to install and configure firewalld | `False` | +|`activemq_shared_storage`| Use shared filesystem directory for storage | `False` | +|`activemq_shared_storage_path`| Absolute path of shared directory | `{{ activemq_dest }}/{{ activemq_instance_name }}/data/shared` | +|`activemq_shared_storage_mounted`| Whether the systemd unit must require a mounted path (only when using shared storage) | `True` | + + +Example Playbook +---------------- +``` +--- +- hosts: all + roles: + - middleware_automation.amq.activemq_uninstall +``` diff --git a/roles/activemq_uninstall/defaults/main.yml b/roles/activemq_uninstall/defaults/main.yml new file mode 100644 index 0000000..f5cd152 --- /dev/null +++ b/roles/activemq_uninstall/defaults/main.yml @@ -0,0 +1,30 @@ +--- +### Parameters as used with activemq role +activemq_version: 2.34.0 +activemq_archive: "apache-artemis-{{ activemq_version }}-bin.zip" +activemq_installdir: "{{ activemq_dest }}/apache-artemis-{{ activemq_version }}" +activemq_dest: /opt/amq +activemq_service_user: amq-broker +activemq_service_group: amq-broker +activemq_service_user_home: "{{ activemq_dest }}/apache-artemis-{{ activemq_version }}" +activemq_instance_name: amq-broker +activemq_service_pidfile: data/artemis.pid +activemq_configure_firewalld: false +activemq_name: 'Apache ActiveMQ' +activemq_service_name: activemq +activemq_data_directory: "{{ activemq_shared_storage_path if activemq_shared_storage else activemq_dest + '/' + activemq_instance_name + '/data' }}" +activemq_paging_directory: "{{ activemq_data_directory }}/paging" +activemq_bindings_directory: "{{ activemq_data_directory }}/bindings" +activemq_journal_directory: "{{ activemq_data_directory }}/journal" +activemq_large_messages_directory: "{{ activemq_data_directory }}/largemessages" +activemq_shared_storage: false +activemq_shared_storage_mounted: true +activemq_shared_storage_path: "{{ activemq_dest }}/{{ activemq_instance_name }}/data/shared" + +### Parameters specific to uninstall role +# skip user/group deletion +activemq_uninstall_skip_user: false +# skip install zipfile deletion +activemq_uninstall_skip_zipfile: false +# skip artemis install deletion +activemq_uninstall_skip_artemis: false diff --git a/roles/activemq_uninstall/meta/argument_specs.yml b/roles/activemq_uninstall/meta/argument_specs.yml new file mode 100644 index 0000000..910e95b --- /dev/null +++ b/roles/activemq_uninstall/meta/argument_specs.yml @@ -0,0 +1,129 @@ +argument_specs: + main: + options: + activemq_version: + default: "2.34.0" + description: "Apache Artemis version" + type: "str" + activemq_archive: + default: "apache-artemis-{{ activemq_version }}-bin.zip" + description: "Apache Artemis install archive filename" + type: "str" + activemq_installdir: + default: "{{ activemq_dest }}/apache-artemis-{{ activemq_version }}" + description: "Apache Artemis Installation path" + type: "str" + activemq_service_user_home: + default: "{{ activemq_dest }}/apache-artemis-{{ activemq_version }}" + description: "Service user home directory, defaults to artemis installation directory" + type: "str" + activemq_dest: + default: "/opt/activemq" + description: "Root installation directory" + type: "str" + activemq_service_user: + default: "amq-broker" + description: "POSIX user running the service" + type: "str" + activemq_service_group: + default: "amq-broker" + description: "POSIX group running the service" + type: "str" + activemq_instance_name: + default: "amq-broker" + description: "Name of broker instance to deploy" + type: "str" + activemq_service_pidfile: + default: "data/artemis.pid" + description: "PID file for service" + type: "str" + activemq_configure_firewalld: + default: false + description: "Whether to install and configure firewalld" + type: "bool" + activemq_shared_storage: + default: false + description: "Use shared filesystem directory for storage" + type: "bool" + activemq_shared_storage_path: + default: "{{ activemq_dest }}/{{ activemq_instance_name }}/data/shared" + description: "Absolute path of shared directory" + type: "str" + activemq_shared_storage_mounted: + default: true + description: "Whether the systemd unit must require a mounted path (only when using shared storage)" + type: "bool" + activemq_name: + description: 'Human friendly name for service' + default: "Apache ActiveMQ" + type: "str" + activemq_service_name: + description: "Systemd unit name" + default: "activemq" + type: "str" + activemq_paging_directory: + description: 'The directory to store paged messages in' + default: 'data/paging' + type: "str" + activemq_bindings_directory: + description: 'The folder in use for the bindings folder' + default: 'data/bindings' + type: "str" + activemq_journal_directory: + description: 'The directory to store the journal files in' + default: 'data/journal' + type: "str" + activemq_large_messages_directory: + description: 'The directory to store large messages' + default: 'data/largemessages' + type: "str" + activemq_journal_datasync: + description: 'Whether to use msync/fsync on journal operations' + default: true + type: 'bool' + activemq_data_directory: + description: "The activemq data directory path" + default: "{{ activemq_shared_storage_path if activemq_shared_storage else activemq_dest + '/' + activemq_instance_name + '/data' }}" + type: 'str' + activemq_uninstall_skip_user: + description: 'Whether to skip user/group account deletion' + default: false + type: 'bool' + activemq_uninstall_skip_zipfile: + description: 'Whether to skip installation zipfile deletion' + default: false + type: 'bool' + activemq_uninstall_skip_artemis: + description: 'Whether to skip artemis directory deletion' + default: false + type: 'bool' + downstream: + options: + amq_broker_version: + default: "7.12.0" + description: "Red Hat AMQ Broker version" + type: "str" + amq_broker_enable: + default: true + description: "Enable installation of Red Hat AMQ Broker" + type: "bool" + amq_broker_archive: + default: "amq-broker-{{ amq_broker_version }}-bin.zip" + description: "Red Hat AMQ Broker install archive filename" + type: "str" + amq_broker_installdir: + default: "{{ amq_broker_dest }}/amq-broker-{{ amq_broker_version }}" + description: "Red Hat AMQ Broker installation path" + type: "str" + amq_broker_dest: + default: "/opt/amq" + description: "Root installation directory" + type: "str" + amq_broker_name: + description: "Human friendly name for service" + default: "Red Hat AMQ Broker" + type: "str" + amq_broker_service_name: + description: "Systemd unit name" + default: "amq_broker" + type: "str" diff --git a/roles/activemq_uninstall/meta/main.yml b/roles/activemq_uninstall/meta/main.yml new file mode 100644 index 0000000..f20a401 --- /dev/null +++ b/roles/activemq_uninstall/meta/main.yml @@ -0,0 +1,31 @@ +--- +collections: + - middleware_automation.common + - ansible.posix + +galaxy_info: + role_name: activemq_uninstall + namespace: middleware_automation + author: Guido Grazioli + description: Uninstalls an ActiveMQ service installed by the activemq role. + company: Red Hat, Inc. + + license: Apache License 2.0 + + min_ansible_version: "2.15" + + platforms: + - name: EL + versions: + - "8" + - "9" + + galaxy_tags: + - activemq + - broker + - redhat + - rhel + - server + - messaging + - messagebus + - infrastructure diff --git a/roles/activemq_uninstall/tasks/main.yml b/roles/activemq_uninstall/tasks/main.yml new file mode 100644 index 0000000..e8415f9 --- /dev/null +++ b/roles/activemq_uninstall/tasks/main.yml @@ -0,0 +1,10 @@ +--- +- name: Include systemd tasks + ansible.builtin.include_tasks: systemd.yml + tags: + - systemd + +- name: Include uninstall tasks + ansible.builtin.include_tasks: uninstall.yml + tags: + - uninstall diff --git a/roles/activemq_uninstall/tasks/systemd.yml b/roles/activemq_uninstall/tasks/systemd.yml new file mode 100644 index 0000000..921c94d --- /dev/null +++ b/roles/activemq_uninstall/tasks/systemd.yml @@ -0,0 +1,36 @@ +--- +- name: Check systemd service + ansible.builtin.service_facts: + +- name: "Disable and stop instance {{ activemq.instance_name }} for {{ activemq.service_name }} service" + become: true + ansible.builtin.systemd: + name: "{{ activemq.instance_name }}" + enabled: false + state: stopped + when: '"{{ activemq.service_name }}.service" in ansible_facts.services' + +- name: "Delete sysconfig file for {{ activemq.instance_name }} {{ activemq.service_name }} service" + become: true + ansible.builtin.file: + state: absent + dest: "/etc/sysconfig/{{ activemq.instance_name }}" + +- name: "Delete systemd unit file for {{ activemq.instance_name }} {{ activemq.service_name }} service" + become: true + ansible.builtin.file: + state: absent + dest: "/etc/systemd/system/{{ activemq.instance_name }}.service" + register: systemdunit + +- name: Reload systemd + become: true + ansible.builtin.systemd: # noqa no-handler definitely not a candidate for a handler + daemon_reload: true + changed_when: systemdunit.changed + +- name: Delete instance directory + become: true + ansible.builtin.file: + state: absent + dest: "{{ activemq.instance_home }}" diff --git a/roles/activemq_uninstall/tasks/uninstall.yml b/roles/activemq_uninstall/tasks/uninstall.yml new file mode 100644 index 0000000..4bc8d22 --- /dev/null +++ b/roles/activemq_uninstall/tasks/uninstall.yml @@ -0,0 +1,69 @@ +--- +- name: "Delete service user" + become: true + ansible.builtin.user: + state: absent + name: "{{ activemq_service_user }}" + when: not activemq_uninstall_skip_user + +- name: "Delete service group" + become: true + ansible.builtin.group: + name: "{{ activemq_service_group }}" + state: absent + when: not activemq_uninstall_skip_user + +- name: "Delete {{ activemq.service_name }} install location" + become: true + ansible.builtin.file: + dest: "{{ activemq_dest }}" + state: absent + +- name: Set download archive path + ansible.builtin.set_fact: + archive: "{{ activemq_dest }}/{{ activemq.bundle }}" + +- name: Check download archive path + become: true + ansible.builtin.stat: + path: "{{ archive }}" + register: archive_path + +- name: Delete archive from target nodes + become: true + ansible.builtin.file: + dest: "{{ archive }}" + state: absent + when: not activemq_uninstall_skip_zipfile + +- name: "Check target directory: {{ activemq.home }}" + become: true + ansible.builtin.stat: + path: "{{ activemq.home }}" + register: path_to_workdir + +- name: "Delete artemis installation directory" + become: true + ansible.builtin.file: + dest: "{{ activemq.home }}" + state: absent + when: not activemq_uninstall_skip_artemis + +- name: Link zipfile directory to wanted directory + become: true + ansible.builtin.file: + state: absent + dest: "{{ activemq.home }}" + when: not activemq_uninstall_skip_artemis + +- name: Link default logs directory + become: true + ansible.builtin.file: + state: absent + dest: "/var/log/{{ activemq.service_name }}/{{ activemq.instance_name }}" + +- name: Create default logs directory + become: true + ansible.builtin.file: + state: absent + dest: "/var/log/{{ activemq.service_name }}" diff --git a/roles/activemq_uninstall/vars/main.yml b/roles/activemq_uninstall/vars/main.yml new file mode 100644 index 0000000..e596feb --- /dev/null +++ b/roles/activemq_uninstall/vars/main.yml @@ -0,0 +1,11 @@ +--- +### internal variables +activemq: # noqa var-naming false positive + home: "{{ activemq_installdir }}" + user_home: "{{ activemq_service_user_home }}" + version: "{{ activemq_version }}" + bundle: "{{ activemq_archive }}" + name: "{{ activemq_name }}" + service_name: "{{ activemq_service_name }}" + instance_name: "{{ activemq_instance_name }}" + instance_home: "{{ activemq_dest }}/{{ activemq_instance_name }}" From 4edba6d959d86773e34b198f56ddc01e443db84e Mon Sep 17 00:00:00 2001 From: Guido Grazioli Date: Mon, 19 Aug 2024 11:06:12 +0200 Subject: [PATCH 2/6] Add uninstall test scenario --- molecule/uninstall/converge.yml | 8 ++++ molecule/uninstall/molecule.yml | 47 +++++++++++++++++++++++ molecule/uninstall/prepare.yml | 67 +++++++++++++++++++++++++++++++++ molecule/uninstall/roles | 1 + molecule/uninstall/verify.yml | 35 +++++++++++++++++ 5 files changed, 158 insertions(+) create mode 100644 molecule/uninstall/converge.yml create mode 100644 molecule/uninstall/molecule.yml create mode 100644 molecule/uninstall/prepare.yml create mode 120000 molecule/uninstall/roles create mode 100644 molecule/uninstall/verify.yml diff --git a/molecule/uninstall/converge.yml b/molecule/uninstall/converge.yml new file mode 100644 index 0000000..e0bde0d --- /dev/null +++ b/molecule/uninstall/converge.yml @@ -0,0 +1,8 @@ +--- +- name: Converge + hosts: all + gather_facts: yes + vars: + activemq_service_user_home: /home/activemq + roles: + - middleware_automation.amq.activemq_uninstall diff --git a/molecule/uninstall/molecule.yml b/molecule/uninstall/molecule.yml new file mode 100644 index 0000000..92a808f --- /dev/null +++ b/molecule/uninstall/molecule.yml @@ -0,0 +1,47 @@ +--- +driver: + name: docker +platforms: + - name: instance + image: registry.access.redhat.com/ubi9/ubi-init:latest + pre_build_image: true + privileged: true + command: "/usr/sbin/init" + tmpfs: + - /run + - /tmp + port_bindings: + - 8161:8161 + published_ports: + - 0.0.0.0:8161:8161/TCP +provisioner: + name: ansible + config_options: + defaults: + interpreter_python: auto_silent + ssh_connection: + pipelining: false + playbooks: + prepare: prepare.yml + converge: converge.yml + verify: verify.yml + inventory: + host_vars: + localhost: + ansible_python_interpreter: "{{ ansible_playbook_python }}" + env: + ANSIBLE_FORCE_COLOR: "true" +verifier: + name: ansible +scenario: + test_sequence: + - cleanup + - destroy + - create + - prepare + - converge + - idempotence + - side_effect + - verify + - cleanup + - destroy diff --git a/molecule/uninstall/prepare.yml b/molecule/uninstall/prepare.yml new file mode 100644 index 0000000..96a4d71 --- /dev/null +++ b/molecule/uninstall/prepare.yml @@ -0,0 +1,67 @@ +--- +- name: Prepare + hosts: all + tasks: + - name: "Run preparation common to all scenario" + ansible.builtin.include_tasks: ../prepare.yml + +- name: Install + hosts: all + gather_facts: yes + vars: + activemq_service_user_home: /home/activemq + activemq_hawtio_role: admin + activemq_users: + - user: amq + password: amqbrokerpass + roles: [ admin ] + - user: other + password: amqotherpass + roles: [ consumer, producer ] + activemq_roles: + - name: admin + permissions: [ createNonDurableQueue, deleteNonDurableQueue, createDurableQueue, deleteDurableQueue, createAddress, deleteAddress, consume, browse, send, manage ] + - name: manager + permissions: [ browse, manage ] + - name: topicsmanager + match: topics.# + permissions: [ createNonDurableQueue, deleteNonDurableQueue, createDurableQueue, deleteDurableQueue, browse, manage ] + - name: consumer + match: topics.# + permissions: [ consume, browse ] + - name: producer + match: topics.# + permissions: [ send, browse ] + activemq_acceptors: + - name: artemis + bind_address: "{{ activemq_host }}" + bind_port: "{{ activemq_port }}" + parameters: + tcpSendBufferSize: 1048576 + tcpReceiveBufferSize: 1048576 + protocols: CORE,MQTT + useEpoll: true + - name: amqp + scheme: tcp + bind_address: "{{ activemq_host }}" + bind_port: "{{ activemq_port_amqp }}" + parameters: + tcpSendBufferSize: 1048576 + tcpReceiveBufferSize: 1048576 + protocols: AMQP + useEpoll: true + amqpMinLargeMessageSize: 102400 + amqpCredits: 1000 + amqpLowCredits: 300 + amqpDuplicateDetection: true + - name: invm + scheme: vm + activemq_diverts: + - name: TESTDIVERT + address: queue.in + forwarding_address: queue.out + routing_type: ANYCAST + filter: "msgType LIKE '%ff%'" + exclusive: True + roles: + - middleware_automation.amq.activemq diff --git a/molecule/uninstall/roles b/molecule/uninstall/roles new file mode 120000 index 0000000..b741aa3 --- /dev/null +++ b/molecule/uninstall/roles @@ -0,0 +1 @@ +../../roles \ No newline at end of file diff --git a/molecule/uninstall/verify.yml b/molecule/uninstall/verify.yml new file mode 100644 index 0000000..7faea66 --- /dev/null +++ b/molecule/uninstall/verify.yml @@ -0,0 +1,35 @@ +--- +- name: Verify + hosts: all + become: yes + tasks: + - name: Populate service facts + ansible.builtin.service_facts: + + - name: Check if amq-broker service is started + ansible.builtin.assert: + that: + - '"amq-broker.service" not in ansible_facts.services' + + - name: Check install dir + ansible.builtin.stat: + path: /opt/amq/amq-broker/ + register: broker_bin + + - name: Check install dir + ansible.builtin.stat: + path: /opt/amq/ + register: broker_artemis + + - name: Check user homedir + ansible.builtin.stat: + path: /home/activemq + register: broker_user + + - name: Verify uninstall + ansible.builtin.assert: + that: + - not broker_user.stat.exists or activemq_uninstall_skip_user + - not broker_artemis.stat.exists or activemq_uninstall_skip_artemis + - not broker_bin.stat.exists + quiet: true From 05ff52c437154d3f11b744f0624b41b6677c8144 Mon Sep 17 00:00:00 2001 From: Guido Grazioli Date: Mon, 19 Aug 2024 11:06:36 +0200 Subject: [PATCH 3/6] Bump minor --- galaxy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxy.yml b/galaxy.yml index 515b4b6..0f3b4f2 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: middleware_automation name: amq -version: "2.1.2" +version: "2.2.0" readme: README.md authors: - Guido Grazioli From 97feff1c58dff322be2c6f2372c005c00f9724ea Mon Sep 17 00:00:00 2001 From: Guido Grazioli Date: Mon, 19 Aug 2024 11:12:11 +0200 Subject: [PATCH 4/6] linter --- roles/activemq_uninstall/tasks/systemd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/activemq_uninstall/tasks/systemd.yml b/roles/activemq_uninstall/tasks/systemd.yml index 921c94d..d4d896e 100644 --- a/roles/activemq_uninstall/tasks/systemd.yml +++ b/roles/activemq_uninstall/tasks/systemd.yml @@ -8,7 +8,7 @@ name: "{{ activemq.instance_name }}" enabled: false state: stopped - when: '"{{ activemq.service_name }}.service" in ansible_facts.services' + when: 'activemq.service_name + ".service" in ansible_facts.services' - name: "Delete sysconfig file for {{ activemq.instance_name }} {{ activemq.service_name }} service" become: true From 12e8da370479c25051cefee557df51d8c33976a3 Mon Sep 17 00:00:00 2001 From: Guido Grazioli Date: Mon, 19 Aug 2024 11:12:58 +0200 Subject: [PATCH 5/6] add test scenario to CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2d5c24..faff48a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,4 +16,4 @@ jobs: with: fqcn: 'middleware_automation/amq' molecule_tests: >- - [ "default", "static_cluster", "amq_upgrade", "mask_passwords", "custom_xml" ] + [ "default", "static_cluster", "amq_upgrade", "mask_passwords", "custom_xml", "uninstall" ] From 2a4e0650d3d39e77b54bea246357166bab550d48 Mon Sep 17 00:00:00 2001 From: Guido Grazioli Date: Mon, 19 Aug 2024 11:25:27 +0200 Subject: [PATCH 6/6] fix typo in parameter --- roles/activemq_uninstall/tasks/systemd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/activemq_uninstall/tasks/systemd.yml b/roles/activemq_uninstall/tasks/systemd.yml index d4d896e..5204f07 100644 --- a/roles/activemq_uninstall/tasks/systemd.yml +++ b/roles/activemq_uninstall/tasks/systemd.yml @@ -8,7 +8,7 @@ name: "{{ activemq.instance_name }}" enabled: false state: stopped - when: 'activemq.service_name + ".service" in ansible_facts.services' + when: 'activemq.instance_name + ".service" in ansible_facts.services' - name: "Delete sysconfig file for {{ activemq.instance_name }} {{ activemq.service_name }} service" become: true