From 24395ee3c9b3418da373f4428b7412f5be42d71a Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 4 Oct 2024 13:42:33 +0200 Subject: [PATCH] [roles/base/systemd/enable-and-start] util to enable + (re)start service and record systemd-preset --- .../enable-and-start/defaults/main.yml | 10 ++++++ .../systemd/enable-and-start/tasks/main.yml | 31 +++++++++++++++++++ .../templates/10-somesible-service.preset.j2 | 9 ++++++ 3 files changed, 50 insertions(+) create mode 100644 roles/base/systemd/enable-and-start/defaults/main.yml create mode 100644 roles/base/systemd/enable-and-start/tasks/main.yml create mode 100644 roles/base/systemd/enable-and-start/templates/10-somesible-service.preset.j2 diff --git a/roles/base/systemd/enable-and-start/defaults/main.yml b/roles/base/systemd/enable-and-start/defaults/main.yml new file mode 100644 index 0000000..5293ce7 --- /dev/null +++ b/roles/base/systemd/enable-and-start/defaults/main.yml @@ -0,0 +1,10 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +# If not overridden in inventory or as a parameter, this is the value that will be used +# +--- +service_state: started diff --git a/roles/base/systemd/enable-and-start/tasks/main.yml b/roles/base/systemd/enable-and-start/tasks/main.yml new file mode 100644 index 0000000..91579a4 --- /dev/null +++ b/roles/base/systemd/enable-and-start/tasks/main.yml @@ -0,0 +1,31 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +--- +- name: "setup enabling preset for {{ service_name }}" + template: + src: "{{item}}" + dest: "/etc/systemd/system-preset/10-somesible-{{ service_name }}.preset" + mode: 0644 + owner: "root" + group: "root" + with_first_found: + - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/10-somesible-service.preset.j2" + - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/10-somesible-service.preset.j2" + - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/10-somesible-service.preset.j2" + - "templates/10-somesible-service.preset.j2" + when: not '@' in service_name + tags: ['systemd', 'systemd-enable-and-start'] + + +- name: "enable and start {{ service_name }}" + systemd: + name: "{{ service_name }}" + daemon_reload: yes + enabled: yes + state: "{{ service_state }}" + tags: ['systemd', 'systemd-enable-and-start'] + ignore_errors: yes diff --git a/roles/base/systemd/enable-and-start/templates/10-somesible-service.preset.j2 b/roles/base/systemd/enable-and-start/templates/10-somesible-service.preset.j2 new file mode 100644 index 0000000..3f5050a --- /dev/null +++ b/roles/base/systemd/enable-and-start/templates/10-somesible-service.preset.j2 @@ -0,0 +1,9 @@ +# +################################################ +### Managed by someone's ansible provisioner ### +################################################ +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# + +enable {{service_name}} -- 2.43.0