ansible

How can i get Ansible to wait until a service is active?


I can check if a service is started(as below), but how do i use the service facts in Ansible to loop\wait until a service is active?

  - name: Ensure myservice is in a running state
    service:
      name: myservice 
      state: started

Solution

  • This is very similar to @zigarn's answer above. In my case it was not enough to know that the service was started or running, I needed to know it was active, hence I'm posting what I went with. Thank you to all for your help

    - name: Ensure myservice is in a running state
        service:
          name: myservice 
          state: started
        register: myserviceDetails
        until: myserviceDetails.status.ActiveState == "active"
        retries: 15
        delay: 20