如果Nginx已停止,则打印“ Nginx已停止,正在修补” 。
如何编写Nginx停止的条件Nginx==0
?
---
- hosts: backend
become: true
become_user: root
become_method: sudo
tasks:
- name: Patching the back-end servers
shell: if nginx == 0 echo "patching has started" fi
答案 0 :(得分:1)
您必须在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'"