diff --git a/playbooks/systemd.yml b/playbooks/systemd.yml index 7d609eb..4d05522 100644 --- a/playbooks/systemd.yml +++ b/playbooks/systemd.yml @@ -14,13 +14,12 @@ prompt: "State of service" private: no tasks: - - name: Check if service exists - shell: systemctl list-units --type=service --all | grep -o "{{ service }}" - register: status - ignore_errors: true - - name: Change state of service - systemd: + - name: Gather service facts + ansible.builtin.service_facts: + + - name: Manage service if present + ansible.builtin.systemd: name: "{{ service }}" - enabled: "{{ enable }}" + enabled: "{{ enable | bool }}" state: "{{ state }}" - when: status.stdout == "{{ service }}" + when: service in ansible_facts.services