From 7ccc51aad5ea52b26b27faf6d00413c94bf02f46 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 7 Aug 2023 11:06:33 +0200 Subject: factor out systemd service editing --- roles/linux_status/tasks/main.yml | 27 +++++-------------------- roles/systemd_edit/tasks/main.yml | 23 +++++++++++++++++++++ roles/systemd_requires_mount/tasks/main.yml | 22 -------------------- roles/systemd_requires_mount_for/tasks/main.yml | 6 ++++++ 4 files changed, 34 insertions(+), 44 deletions(-) create mode 100644 roles/systemd_edit/tasks/main.yml delete mode 100644 roles/systemd_requires_mount/tasks/main.yml create mode 100644 roles/systemd_requires_mount_for/tasks/main.yml (limited to 'roles') diff --git a/roles/linux_status/tasks/main.yml b/roles/linux_status/tasks/main.yml index 6ce23f9..1383699 100644 --- a/roles/linux_status/tasks/main.yml +++ b/roles/linux_status/tasks/main.yml @@ -15,27 +15,10 @@ - name: Disable power management when: linux_status_disable_power_management - become: true + ansible.builtin.include_role: + name: systemd_edit vars: service_name: linux-status - block: - - name: 'Create override directory: {{ service_name }}' - ansible.builtin.file: - path: '/etc/systemd/system/{{ service_name }}.service.d' - state: directory - - - name: 'Set up override: {{ service_name }}' - community.general.ini_file: - dest: '/etc/systemd/system/{{ service_name }}.service.d/override.conf' - section: Unit - option: ExecStart - values: ['', '/usr/bin/python3 -B server.py --disable-power'] - no_extra_spaces: true - register: overridden - - - name: 'Restart service: {{ service_name }}' - ansible.builtin.systemd_service: - daemon_reload: true - name: '{{ service_name }}' - state: restarted - when: overridden.changed + service_section: Service + service_option: ExecStart + service_values: ['', '/usr/bin/python3 -B server.py --disable-power'] diff --git a/roles/systemd_edit/tasks/main.yml b/roles/systemd_edit/tasks/main.yml new file mode 100644 index 0000000..06a0a8a --- /dev/null +++ b/roles/systemd_edit/tasks/main.yml @@ -0,0 +1,23 @@ +- name: Edit systemd service definition + become: true + block: + - name: 'Create override directory: {{ service_name }}' + ansible.builtin.file: + path: '/etc/systemd/system/{{ service_name }}.service.d' + state: directory + + - name: 'Set up override: {{ service_name }}' + community.general.ini_file: + dest: '/etc/systemd/system/{{ service_name }}.service.d/override.conf' + section: '{{ service_section }}' + option: '{{ service_option }}' + values: '{{ service_values }}' + no_extra_spaces: true + register: overridden + + - name: 'Restart service: {{ service_name }}' + ansible.builtin.systemd_service: + daemon_reload: true + name: '{{ service_name }}' + state: restarted + when: overridden.changed diff --git a/roles/systemd_requires_mount/tasks/main.yml b/roles/systemd_requires_mount/tasks/main.yml deleted file mode 100644 index cd4beb3..0000000 --- a/roles/systemd_requires_mount/tasks/main.yml +++ /dev/null @@ -1,22 +0,0 @@ -- name: Set up systemd service dependency - become: true - block: - - name: 'Create override directory: {{ service_name }}' - ansible.builtin.file: - path: '/etc/systemd/system/{{ service_name }}.service.d' - state: directory - - - name: 'Set up override: {{ service_name }}' - community.general.ini_file: - dest: '/etc/systemd/system/{{ service_name }}.service.d/override.conf' - section: Unit - option: RequiresMountsFor - value: '{{ mount_dir }}' - register: overridden - - - name: 'Restart service: {{ service_name }}' - ansible.builtin.systemd_service: - daemon_reload: true - name: '{{ service_name }}' - state: restarted - when: overridden.changed diff --git a/roles/systemd_requires_mount_for/tasks/main.yml b/roles/systemd_requires_mount_for/tasks/main.yml new file mode 100644 index 0000000..71db6e4 --- /dev/null +++ b/roles/systemd_requires_mount_for/tasks/main.yml @@ -0,0 +1,6 @@ +- ansible.builtin.include_role: + name: systemd_edit + vars: + service_section: Unit + service_option: RequiresMountFor + service_values: ['{{ mount_dir }}'] -- cgit v1.2.3