当 bootstrap 集群脚本永远运行时,如何移动到下一个 ansible 任务?
How to move to next ansible task as bootstrap cluster script runs forever?
我对 bootstrap 5 个集群节点的 ansible 任务有效,但是如何配置我的任务以继续执行剧本中的其余任务,因为它被 bootstrapping 节点挂起.
如果您不需要等待任务完成,您可以通过指定轮询值 0:
异步地运行任务
请检查示例。第一个任务是 sleep 60 命令,你会注意到 ansible 转移到下一个任务,而 sleep 命令仍在主机上执行。
[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]#
我对 bootstrap 5 个集群节点的 ansible 任务有效,但是如何配置我的任务以继续执行剧本中的其余任务,因为它被 bootstrapping 节点挂起.
如果您不需要等待任务完成,您可以通过指定轮询值 0:
异步地运行任务请检查示例。第一个任务是 sleep 60 命令,你会注意到 ansible 转移到下一个任务,而 sleep 命令仍在主机上执行。
[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]#