mirror of https://github.com/ansible/ansible.git
Extend systemctl is-enabled check to handle "enabled-runtime" too. (#77754)
In general the existence of a runtime-enabled unit should not prevent a persistent enable being set. Specifically this handles the case where there is an entry in fstab for a mount point (which is retained to allow manual mount/umount to take place) and yet a systemd mount unit needs to be deployed to handle other unit options. There will be a generator-created unit file which shows the unit as enabled-runtime and the persistent enable of the mount unit will fail. Additionally improve the comments and modify the code to use rsplit() and the "in" notation since "systemctl is-enabled" is documented to return specific values in the cases of interest. --------- Signed-off-by: David Greaves <david@dgreaves.com> Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>pull/83012/head
parent
d304fd86c2
commit
3076478892
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- systemd - extend systemctl is-enabled check to handle "enabled-runtime" (https://github.com/ansible/ansible/pull/77754).
|
@ -0,0 +1,50 @@
|
|||||||
|
- name: Copy enabled-runtime service file
|
||||||
|
template:
|
||||||
|
src: baz.service
|
||||||
|
dest: /etc/systemd/system/baz.service
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0644'
|
||||||
|
notify: remove unit file
|
||||||
|
|
||||||
|
- name: Reload systemd
|
||||||
|
systemd:
|
||||||
|
daemon_reload: true
|
||||||
|
|
||||||
|
- name: Enable the enabled-runtime service using shell command
|
||||||
|
shell: systemctl enable --runtime baz
|
||||||
|
|
||||||
|
- name: Enable enabled-runtime service
|
||||||
|
systemd:
|
||||||
|
name: baz.service
|
||||||
|
enabled: true
|
||||||
|
register: baz_test_1
|
||||||
|
|
||||||
|
- name: Enable enabled-runtime service again
|
||||||
|
systemd:
|
||||||
|
name: baz.service
|
||||||
|
enabled: true
|
||||||
|
register: baz_test_2
|
||||||
|
|
||||||
|
- name: Disable enabled-runtime service
|
||||||
|
systemd:
|
||||||
|
name: baz.service
|
||||||
|
state: stopped
|
||||||
|
enabled: false
|
||||||
|
register: baz_test_3
|
||||||
|
|
||||||
|
- name: Disable enabled-runtime service again
|
||||||
|
systemd:
|
||||||
|
name: baz.service
|
||||||
|
enabled: false
|
||||||
|
register: baz_test_4
|
||||||
|
|
||||||
|
- name:
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- baz_test_1 is changed
|
||||||
|
- baz_test_1 is success
|
||||||
|
- baz_test_2 is not changed
|
||||||
|
- baz_test_2 is success
|
||||||
|
- baz_test_3 is changed
|
||||||
|
- baz_test_4 is not changed
|
@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Baz Server
|
||||||
|
Documentation=Baz
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/bin/yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
Loading…
Reference in New Issue