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 private: no
tasks: tasks:
- name: Check if service exists - name: Check if service exists
stat: path=/usr/lib/systemd/system/{{ service }} shell: systemctl list-units --type=service --all | grep -o "{{ service }}"
register: status register: status
ignore_errors: yes ignore_errors: true
- name: Change state of service - name: Change state of service
systemd: systemd:
name: "{{ service }}" name: "{{ service }}"
enabled: "{{ enable }}" enabled: "{{ enable }}"
state: "{{ state }}" state: "{{ state }}"
when: status.stat.exists when: status.stdout == "{{ service }}"