mirror of https://github.com/ansible/ansible.git
systemd - do not overwrite unit name when searching (#72985)
* systemd - do not overwrite unit name when searching PR #72702 introduced a bug that changed the unit name when splitting it up for the purpose of searching for the unit. This only happens on unit file templates on systems that have a 5.8 or newer kernel and a version of systemd that does not contain a bugfix that causes systmed to fail to parse dbus. * Use facts rather than a manual probe to determine if systmed is present * Remov unnecessary block * Use vars files instead of set_fact * Add tests for using a templated unit file * Update changelog fragment * Use template to get correct path to sleep binarypull/73017/head
parent
13bf04e95a
commit
48803604cd
@ -0,0 +1,4 @@
|
|||||||
|
bugfixes:
|
||||||
|
- >
|
||||||
|
systemd - preserve the full unit name when using a templated service and
|
||||||
|
``systemd`` failed to parse dbus due to a known bug in ``systemd`` (https://github.com/ansible/ansible/pull/72985)
|
@ -0,0 +1,4 @@
|
|||||||
|
- name: remove unit file
|
||||||
|
file:
|
||||||
|
path: /etc/systemd/system/sleeper@.service
|
||||||
|
state: absent
|
@ -0,0 +1,50 @@
|
|||||||
|
- name: Copy service file
|
||||||
|
template:
|
||||||
|
src: sleeper@.service
|
||||||
|
dest: /etc/systemd/system/sleeper@.service
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0644'
|
||||||
|
notify: remove unit file
|
||||||
|
|
||||||
|
- name: Reload systemd
|
||||||
|
systemd:
|
||||||
|
daemon_reload: yes
|
||||||
|
|
||||||
|
- name: Start and enable service using unit template
|
||||||
|
systemd:
|
||||||
|
name: sleeper@100.service
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
register: template_test_1
|
||||||
|
|
||||||
|
- name: Start and enable service using unit template again
|
||||||
|
systemd:
|
||||||
|
name: sleeper@100.service
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
register: template_test_2
|
||||||
|
|
||||||
|
- name: Stop and disable service using unit template
|
||||||
|
systemd:
|
||||||
|
name: sleeper@100.service
|
||||||
|
state: stopped
|
||||||
|
enabled: no
|
||||||
|
register: template_test_3
|
||||||
|
|
||||||
|
- name: Stop and disable service using unit template again
|
||||||
|
systemd:
|
||||||
|
name: sleeper@100.service
|
||||||
|
state: stopped
|
||||||
|
enabled: no
|
||||||
|
register: template_test_4
|
||||||
|
|
||||||
|
- name:
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template_test_1 is changed
|
||||||
|
- template_test_1 is success
|
||||||
|
- template_test_2 is not changed
|
||||||
|
- template_test_2 is success
|
||||||
|
- template_test_3 is changed
|
||||||
|
- template_test_4 is not changed
|
@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Basic service to use as a template
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart={{ sleep_bin_path }} %i
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -0,0 +1,2 @@
|
|||||||
|
ssh_service: ssh
|
||||||
|
sleep_bin_path: /bin/sleep
|
@ -0,0 +1,2 @@
|
|||||||
|
ssh_service: sshd
|
||||||
|
sleep_bin_path: /usr/bin/sleep
|
Loading…
Reference in New Issue