小编典典

如何使用Ansible等待服务器重启?

linux

我正在尝试重新启动服务器,然后使用以下命令等待:

- name: Restart server
  shell: reboot

- name: Wait for server to restart
  wait_for:
    port=22
    delay=1
    timeout=300

但是我得到这个错误:

TASK: [iptables | Wait for server to restart] ********************************* 
fatal: [example.com] => failed to transfer file to /root/.ansible/tmp/ansible-tmp-1401138291.69-222045017562709/wait_for:
sftp> put /tmp/tmpApPR8k /root/.ansible/tmp/ansible-tmp-1401138291.69-222045017562709/wait_for

Connected to example.com.
Connection closed

阅读 1153

收藏
2020-06-03

共1个答案

小编典典

您应该将wait_for任务更改为local_action,然后指定要等待的主机。例如:

- name: Wait for server to restart
  local_action:
    module: wait_for
      host=192.168.50.4
      port=22
      delay=1
      timeout=300
2020-06-03