From 587c44ce2f7fa0a1e1da9cd874a4d60787233e7f Mon Sep 17 00:00:00 2001 From: Giovanni Toraldo Date: Tue, 26 Nov 2024 15:46:28 +0100 Subject: [PATCH] Get rid of separate role which is unusable with the current structure --- .github/workflows/community.yml | 1 - roles/audit_storage/defaults/main.yml | 13 ++ roles/audit_storage/handlers/main.yml | 9 ++ roles/audit_storage/tasks/main.yml | 25 ++-- .../templates/systemd-service.j2 | 31 +++++ roles/audit_storage/vars/main.yml | 3 + roles/systemd_service/README.md | 118 ------------------ roles/systemd_service/defaults/main.yml | 15 --- roles/systemd_service/handlers/main.yml | 11 -- roles/systemd_service/meta/argument_specs.yml | 54 -------- roles/systemd_service/meta/main.yml | 15 --- .../molecule/default/converge.yml | 15 --- .../molecule/default/molecule.yml | 15 --- .../molecule/default/verify.yml | 26 ---- roles/systemd_service/tasks/main.yml | 16 --- .../templates/systemd-service.j2 | 31 ----- roles/systemd_service/vars/main.yml | 2 - 17 files changed, 70 insertions(+), 330 deletions(-) create mode 100644 roles/audit_storage/templates/systemd-service.j2 delete mode 100644 roles/systemd_service/README.md delete mode 100644 roles/systemd_service/defaults/main.yml delete mode 100644 roles/systemd_service/handlers/main.yml delete mode 100644 roles/systemd_service/meta/argument_specs.yml delete mode 100644 roles/systemd_service/meta/main.yml delete mode 100644 roles/systemd_service/molecule/default/converge.yml delete mode 100644 roles/systemd_service/molecule/default/molecule.yml delete mode 100644 roles/systemd_service/molecule/default/verify.yml delete mode 100644 roles/systemd_service/tasks/main.yml delete mode 100644 roles/systemd_service/templates/systemd-service.j2 delete mode 100644 roles/systemd_service/vars/main.yml diff --git a/.github/workflows/community.yml b/.github/workflows/community.yml index 712ff650b..56f20d8d4 100644 --- a/.github/workflows/community.yml +++ b/.github/workflows/community.yml @@ -44,7 +44,6 @@ jobs: - name: search - name: tomcat - name: transformers - - name: systemd_service env: PY_COLORS: 1 PYTHONUNBUFFERED: 1 diff --git a/roles/audit_storage/defaults/main.yml b/roles/audit_storage/defaults/main.yml index cf31a51bf..61ac4420e 100644 --- a/roles/audit_storage/defaults/main.yml +++ b/roles/audit_storage/defaults/main.yml @@ -30,3 +30,16 @@ audit_storage_java_bin_path: /opt/openjdk-17.0.11/bin/java audit_storage_binaries_dir: "/opt/alfresco/audit-storage-{{ audit_storage_version }}" audit_storage_config_dir: "/etc/alfresco/audit-storage" + +audit_storage_systemd_service_unit_name: "alfresco-audit-storage" +audit_storage_systemd_service_unit_description: "Alfresco Audit Storage" +audit_storage_systemd_service_exec_start: "{{ audit_storage_java_bin_path }} -jar {{ audit_storage_artifact_path }}" +audit_storage_systemd_service_user: "{{ audit_storage_username }}" + +audit_storage_systemd_service_unit_after: syslog.target network.target local-fs.target remote-fs.target nss-lookup.target +audit_storage_systemd_service_type: simple +audit_storage_systemd_service_exec_stop: kill -15 $MAINPID +audit_storage_systemd_service_working_directory: /tmp +audit_storage_systemd_service_additional_options: {} +audit_storage_systemd_service_state: started +audit_storage_systemd_service_enabled: true diff --git a/roles/audit_storage/handlers/main.yml b/roles/audit_storage/handlers/main.yml index 5557d5647..7520a9d9d 100644 --- a/roles/audit_storage/handlers/main.yml +++ b/roles/audit_storage/handlers/main.yml @@ -1,2 +1,11 @@ --- # handlers file for audit_storage +- name: Reload systemd + ansible.builtin.systemd: + daemon_reload: true + +- name: Restart {{ audit_storage_systemd_service_unit_name }} + ansible.builtin.systemd: + name: "{{ audit_storage_systemd_service_unit_name }}" + state: restarted + when: audit_storage_systemd_service_state == 'started' diff --git a/roles/audit_storage/tasks/main.yml b/roles/audit_storage/tasks/main.yml index 321b82c21..8180ff75e 100644 --- a/roles/audit_storage/tasks/main.yml +++ b/roles/audit_storage/tasks/main.yml @@ -32,14 +32,17 @@ owner: "{{ audit_storage_username }}" group: "{{ audit_storage_group_name }}" - - name: Install service - ansible.builtin.include_role: - name: systemd_service - vars: - systemd_service_unit_name: "alfresco-audit-storage" - systemd_service_unit_description: "Alfresco Audit Storage" - systemd_service_exec_start: "{{ audit_storage_java_bin_path }} -jar {{ audit_storage_artifact_path }}" - systemd_service_user: "{{ audit_storage_username }}" - systemd_service_environment: >- - {{ audit_storage_default_environment | - combine(audit_storage_environment) }} + - name: Create systemd service + ansible.builtin.template: + src: systemd-service.j2 + dest: /etc/systemd/system/{{ audit_storage_systemd_service_unit_name }}.service + mode: "0644" + notify: + - Reload systemd + - Restart {{ audit_storage_systemd_service_unit_name }} + + - name: Start service + ansible.builtin.systemd: + name: "{{ audit_storage_systemd_service_unit_name }}" + state: "{{ audit_storage_systemd_service_state }}" + enabled: "{{ audit_storage_systemd_service_enabled }}" diff --git a/roles/audit_storage/templates/systemd-service.j2 b/roles/audit_storage/templates/systemd-service.j2 new file mode 100644 index 000000000..aac9c760e --- /dev/null +++ b/roles/audit_storage/templates/systemd-service.j2 @@ -0,0 +1,31 @@ +[Unit] +Description={{ audit_storage_systemd_service_unit_description }} +After={{ audit_storage_systemd_service_unit_after }} + +[Service] +Type={{ audit_storage_systemd_service_type }} +{% if audit_storage_systemd_service_type == 'oneshot' %} +RemainAfterExit=yes +{% endif %} + +User={{ audit_storage_systemd_service_user }} + +{% for key, value in audit_storage_systemd_service_environment.items() %} +Environment="{{ key }}={{ value | replace('%', '%%') }}" +{% endfor %} + +ExecStart={{ audit_storage_systemd_service_exec_start }} +ExecStop={{ audit_storage_systemd_service_exec_stop }} + +Restart=on-failure +RestartSec=60 +SuccessExitStatus=143 + +WorkingDirectory={{ audit_storage_systemd_service_working_directory }} + +{% for key, value in audit_storage_systemd_service_additional_options.items() %} +{{ key }}={{ value }} +{% endfor %} + +[Install] +WantedBy=multi-user.target diff --git a/roles/audit_storage/vars/main.yml b/roles/audit_storage/vars/main.yml index 0e28f196c..9786eab47 100644 --- a/roles/audit_storage/vars/main.yml +++ b/roles/audit_storage/vars/main.yml @@ -1,3 +1,6 @@ --- # vars file for audit_storage audit_storage_artifact_path: "{{ audit_storage_binaries_dir }}/{{ audit_storage_artifact_name }}-{{ audit_storage_version }}.jar" +audit_storage_systemd_service_environment: >- + {{ audit_storage_default_environment | + combine(audit_storage_environment) }} diff --git a/roles/systemd_service/README.md b/roles/systemd_service/README.md deleted file mode 100644 index 02cf5f87a..000000000 --- a/roles/systemd_service/README.md +++ /dev/null @@ -1,118 +0,0 @@ -# systemd_service - -Install and configure systemd services - -## Table of content - -* [systemd\_service](#systemd_service) - * [Table of content](#table-of-content) - * [Requirements](#requirements) - * [Default Variables](#default-variables) - * [systemd\_service\_additional\_options](#systemd_service_additional_options) - * [systemd\_service\_enabled](#systemd_service_enabled) - * [systemd\_service\_environment](#systemd_service_environment) - * [systemd\_service\_exec\_start](#systemd_service_exec_start) - * [systemd\_service\_exec\_stop](#systemd_service_exec_stop) - * [systemd\_service\_state](#systemd_service_state) - * [systemd\_service\_type](#systemd_service_type) - * [systemd\_service\_unit\_after](#systemd_service_unit_after) - * [systemd\_service\_unit\_description](#systemd_service_unit_description) - * [systemd\_service\_unit\_name](#systemd_service_unit_name) - * [systemd\_service\_user](#systemd_service_user) - * [systemd\_service\_working\_directory](#systemd_service_working_directory) - * [Dependencies](#dependencies) - * [License](#license) - * [Author](#author) - ---- - -## Requirements - -* Minimum Ansible version: `2.1` - -## Default Variables - -### systemd_service_additional_options - -```YAML -systemd_service_additional_options: {} -``` - -### systemd_service_enabled - -```YAML -systemd_service_enabled: true -``` - -### systemd_service_environment - -```YAML -systemd_service_environment: {} -``` - -### systemd_service_exec_start - -```YAML -systemd_service_exec_start: '' -``` - -### systemd_service_exec_stop - -```YAML -systemd_service_exec_stop: kill -15 $MAINPID -``` - -### systemd_service_state - -```YAML -systemd_service_state: started -``` - -### systemd_service_type - -```YAML -systemd_service_type: simple -``` - -### systemd_service_unit_after - -```YAML -systemd_service_unit_after: syslog.target network.target local-fs.target remote-fs.target - nss-lookup.target -``` - -### systemd_service_unit_description - -```YAML -systemd_service_unit_description: '' -``` - -### systemd_service_unit_name - -```YAML -systemd_service_unit_name: '' -``` - -### systemd_service_user - -```YAML -systemd_service_user: '' -``` - -### systemd_service_working_directory - -```YAML -systemd_service_working_directory: /tmp -``` - -## Dependencies - -None. - -## License - -Apache-2.0 - -## Author - -Alfresco Ops Readiness diff --git a/roles/systemd_service/defaults/main.yml b/roles/systemd_service/defaults/main.yml deleted file mode 100644 index 8ac453bf8..000000000 --- a/roles/systemd_service/defaults/main.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -# defaults file for systemd-service -systemd_service_unit_name: '' -systemd_service_unit_description: '' -systemd_service_unit_after: syslog.target network.target local-fs.target remote-fs.target nss-lookup.target - -systemd_service_type: simple -systemd_service_user: '' -systemd_service_environment: {} -systemd_service_exec_start: '' -systemd_service_exec_stop: kill -15 $MAINPID -systemd_service_working_directory: /tmp -systemd_service_additional_options: {} -systemd_service_state: started -systemd_service_enabled: true diff --git a/roles/systemd_service/handlers/main.yml b/roles/systemd_service/handlers/main.yml deleted file mode 100644 index 5cb38574b..000000000 --- a/roles/systemd_service/handlers/main.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -# handlers file for systemd-service -- name: Reload systemd - ansible.builtin.systemd: - daemon_reload: true - -- name: Restart {{ systemd_service_unit_name }} - ansible.builtin.systemd: - name: "{{ systemd_service_unit_name }}" - state: restarted - when: systemd_service_state == 'started' diff --git a/roles/systemd_service/meta/argument_specs.yml b/roles/systemd_service/meta/argument_specs.yml deleted file mode 100644 index 473e6f568..000000000 --- a/roles/systemd_service/meta/argument_specs.yml +++ /dev/null @@ -1,54 +0,0 @@ ---- -argument_specs: - main: - short_description: Install a systemd service unit - description: | - This role installs a systemd service unit and starts it. - options: - systemd_service_unit_name: - type: str - description: Name of the systemd service unit - required: true - systemd_service_unit_description: - type: str - description: Description of the systemd service unit - required: true - systemd_service_unit_after: - type: str - description: List of systemd targets to start after (space separated) - systemd_service_type: - type: str - description: Type of the systemd service unit - default: simple - systemd_service_user: - type: str - description: User to run the systemd service as - required: true - systemd_service_environment: - type: dict - description: Environment variables to set for the systemd service unit - default: {} - systemd_service_exec_start: - type: str - description: Command to start the systemd service unit - required: true - systemd_service_exec_stop: - type: str - description: Command to stop the systemd service unit - default: kill -15 $MAINPID - systemd_service_working_directory: - type: str - description: Working directory for the systemd service unit - default: /tmp - systemd_service_additional_options: - type: dict - description: Additional options to set for the systemd service unit - default: {} - systemd_service_state: - type: str - description: Default state of the systemd service unit - default: started - systemd_service_enabled: - type: bool - description: Whether the systemd service unit should be enabled (started on boot) - default: true diff --git a/roles/systemd_service/meta/main.yml b/roles/systemd_service/meta/main.yml deleted file mode 100644 index 6469276df..000000000 --- a/roles/systemd_service/meta/main.yml +++ /dev/null @@ -1,15 +0,0 @@ -galaxy_info: - author: Alfresco Ops Readiness - description: Install and configure systemd services - company: Hyland - - license: Apache-2.0 - - min_ansible_version: '2.1' - - galaxy_tags: - - systemd - - service - - configuration - -dependencies: [] diff --git a/roles/systemd_service/molecule/default/converge.yml b/roles/systemd_service/molecule/default/converge.yml deleted file mode 100644 index ccc6447a6..000000000 --- a/roles/systemd_service/molecule/default/converge.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -- name: Converge - hosts: all - gather_facts: false - tasks: - - name: Include role - ansible.builtin.include_role: - name: systemd_service - vars: - systemd_service_unit_name: my-test-service - systemd_service_unit_description: My very cool service - systemd_service_exec_start: /bin/sleep infinity - systemd_service_environment: - MY_ENV_VAR: my_value - ANOTHER_ENV_VAR: another_value diff --git a/roles/systemd_service/molecule/default/molecule.yml b/roles/systemd_service/molecule/default/molecule.yml deleted file mode 100644 index 861d895ad..000000000 --- a/roles/systemd_service/molecule/default/molecule.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -driver: - name: docker -platforms: - - name: instance - dockerfile: ../../../../tests/molecule/Dockerfile-noprivs.j2 - image: rockylinux:9 - command: "/lib/systemd/systemd" - privileged: true - tmpfs: - - /run - - /run/lock - - /tmp - volume: - - "/sys/fs/cgroup:/sys/fs/cgroup:ro" diff --git a/roles/systemd_service/molecule/default/verify.yml b/roles/systemd_service/molecule/default/verify.yml deleted file mode 100644 index 01dca08fc..000000000 --- a/roles/systemd_service/molecule/default/verify.yml +++ /dev/null @@ -1,26 +0,0 @@ ---- -- name: Verify - hosts: all - gather_facts: false - tasks: - - name: Check service is running - ansible.builtin.systemd: - name: my-test-service - state: started - - - name: Check service is enabled - ansible.builtin.systemd: - name: my-test-service - enabled: true - - - name: Check logs for warnings and errors - ansible.builtin.command: journalctl -u my-test-service -p 5 - register: journalctl_output - changed_when: false - - - name: Assert logs are clean - ansible.builtin.assert: - that: - - journalctl_output.stdout_lines[0] == '-- No entries --' - fail_msg: "Service logs contain warnings or errors: {{ journalctl_output.stdout }}" - quiet: true diff --git a/roles/systemd_service/tasks/main.yml b/roles/systemd_service/tasks/main.yml deleted file mode 100644 index b2f3811ad..000000000 --- a/roles/systemd_service/tasks/main.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -# tasks file for systemd-service -- name: Create systemd service - ansible.builtin.template: - src: systemd-service.j2 - dest: /etc/systemd/system/{{ systemd_service_unit_name }}.service - mode: "0644" - notify: - - Reload systemd - - Restart {{ systemd_service_unit_name }} - -- name: Start service - ansible.builtin.systemd: - name: "{{ systemd_service_unit_name }}" - state: "{{ systemd_service_state }}" - enabled: "{{ systemd_service_enabled }}" diff --git a/roles/systemd_service/templates/systemd-service.j2 b/roles/systemd_service/templates/systemd-service.j2 deleted file mode 100644 index 659a5506c..000000000 --- a/roles/systemd_service/templates/systemd-service.j2 +++ /dev/null @@ -1,31 +0,0 @@ -[Unit] -Description={{ systemd_service_unit_description }} -After={{ systemd_service_unit_after }} - -[Service] -Type={{ systemd_service_type }} -{% if systemd_service_type == 'oneshot' %} -RemainAfterExit=yes -{% endif %} - -User={{ systemd_service_user }} - -{% for key, value in systemd_service_environment.items() %} -Environment="{{ key }}={{ value | replace('%', '%%') }}" -{% endfor %} - -ExecStart={{ systemd_service_exec_start }} -ExecStop={{ systemd_service_exec_stop }} - -Restart=on-failure -RestartSec=60 -SuccessExitStatus=143 - -WorkingDirectory={{ systemd_service_working_directory }} - -{% for key, value in systemd_service_additional_options.items() %} -{{ key }}={{ value }} -{% endfor %} - -[Install] -WantedBy=multi-user.target diff --git a/roles/systemd_service/vars/main.yml b/roles/systemd_service/vars/main.yml deleted file mode 100644 index 4523ba097..000000000 --- a/roles/systemd_service/vars/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# vars file for systemd-service