Check if service exists with Ansible

后端 未结 6 965
面向向阳花
面向向阳花 2020-12-14 14:12

I have an Ansible playbook for deploying a Java app as an init.d daemon.

Being a beginner in both Ansible and Linux I\'m having trouble to conditionally execute task

6条回答
  •  情书的邮戳
    2020-12-14 14:42

    I modified Florian's answer to only use the return code of the service command (this worked on Mint 18.2)

    - name: Check if Logstash service exist
      shell: service logstash status 
      register: logstash_status
      failed_when: not(logstash_status.rc == 3 or logstash_status.rc == 0)
    
    - name: Check if Logstash service exist
      service:
        name: logstash
        state: stopped 
      when: logstash_status.rc == 0
    

提交回复
热议问题