use shell to determine if service exists

This commit is contained in:
2024-12-14 06:32:14 +00:00
parent f05c40cfd9
commit c6bcb13a68

View File

@@ -15,12 +15,12 @@
private: no
tasks:
- name: Check if service exists
stat: path=/usr/lib/systemd/system/{{ service }}
shell: systemctl list-units --type=service --all | grep -o "{{ service }}"
register: status
ignore_errors: yes
ignore_errors: true
- name: Change state of service
systemd:
name: "{{ service }}"
enabled: "{{ enable }}"
state: "{{ state }}"
when: status.stat.exists
when: status.stdout == "{{ service }}"