Вы должны использовать when conditionnal
для этого:
---
- hosts: backend
become: true
become_user: root
become_method: sudo
tasks:
- name: Patching the back-end servers
shell: echo "patching has started"
when: nginx == 0
Если вы также ищете сам статус услуги, тогда вы ищите service_facts
:
---
- hosts: backend
become: true
become_user: root
become_method: sudo
tasks:
- name: Populate service facts
service_facts:
- name: Patching the back-end servers
shell: echo "patching has started"
when: "services_state.ansible_facts.services['ngnix'].state == 'stopped'"