Search code examples
ansiblenodesetcd

How to move to next ansible task as bootstrap cluster script runs forever?


My ansible task to bootstrap a 5 cluster node works, but how to configure my task to continue executing the rest of tasks in the playbook, as it is hanged by bootstrapping the nodes.


Solution

  • if you do not need to wait on the task to complete, you may run the task asynchronously by specifying a poll value of 0:

    please check example. first task is a sleep 60 command, you will notice ansible moved on to next task while sleep command is still executing on the host.

    [root@optima-ansible ILIAS]# cat testt.yml 
    ---
    - name: test play
      hosts: localhost
      connection: local
      gather_facts: false
      become: yes
      vars:
    
      tasks:
      - name: simulate long running op (15 sec), wait for up to 45 sec, poll every 5 sec
        command: /bin/sleep 60
        async: 45
        poll: 0
    
      - debug:
          msg: "moving on"
    [root@optima-ansible ILIAS]# ansible-playbook testt.yml 
    
    PLAY [test play] *******************************************************************************************************************************************************************************************************
    
    TASK [simulate long running op (15 sec), wait for up to 45 sec, poll every 5 sec] **************************************************************************************************************************************
    changed: [localhost]
    
    TASK [debug] ***********************************************************************************************************************************************************************************************************
    ok: [localhost] => {
        "msg": "moving on"
    }
    
    PLAY RECAP *************************************************************************************************************************************************************************************************************
    localhost                  : ok=2    changed=1    unreachable=0    failed=0   
    
    [root@optima-ansible ILIAS]# ps -ef | grep sleep
    root     10004 10003  0 19:30 ?        00:00:00 /bin/sleep 60
    root     10010  5697  0 19:30 pts/0    00:00:00 grep --color=auto sleep
    [root@optima-ansible ILIAS]#