From c6bcb13a68d083df6c1dea0a9a190bf9d2f12bfb Mon Sep 17 00:00:00 2001 From: aggarwalakshun Date: Sat, 14 Dec 2024 06:32:14 +0000 Subject: [PATCH] use shell to determine if service exists --- playbooks/systemd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/playbooks/systemd.yml b/playbooks/systemd.yml index d97b2f7..7d609eb 100644 --- a/playbooks/systemd.yml +++ b/playbooks/systemd.yml @@ -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 }}"