Help with Playbook

Dears,
I have a doubt, I new verify if exist a service on systemd with playbook.

My part code:

  • name: Stop service puppet-agent
    service:
    name: puppet
    state: stopped
    enabled: no

How Can I verify if existe puppet-agent on systemd, if exists I need to disable service, if no, I would like to pass for next configuration. Any suggestion?

Hi,

Check out service_facts module:

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/service_facts_module.html

Regards

Steve Maher

Or another approach is you can register the output using the register keyword and fetch, and use when condition to do further actions on the basis of that particular output.