this is better

This commit is contained in:
2025-09-15 14:58:36 +00:00
parent 05950028a8
commit 06f7400e61

View File

@@ -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