skip to Main Content

I have a requirement where I need to Restart a set of windows services on a set of hosts sequentially with 60 seconds between service start. Appreciate your help

Order of Services

  1. Polling Agent Service
 wait 60 seconds then start 2) Memcached 
 wait 30 seconds then start 3) watcher

2

Answers


  1. For linux systems, I do the following:

    - name: restart a service one by one, w 60 in between
      shell: systemctl restart my_service ; sleep 60
      throttle: 1
      args:
        warn: false
    

    I assume you can apply the same logic same for windows systems, w sleep/ping/timeout and win_command

    Login or Signup to reply.
  2. You can use loop_control with pause (in seconds).
    https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#pausing-within-a-loop

    One disadventage in your case is, that the pause time is the same with each loop, and not dynamically.

    - name: restart fluent-bit
      ansible.windows.win_service:
        name: "{{ item }}"
        state: restarted
      with_items:
        - Polling Agent Service
        - Memcached
        - watcher
      loop_control:
        pause: 60 # 60 seconds after each item
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search