您如何等待或重试ssh连接?我有一个运行t govc
的ansible tsk,将vm上载到vcenter,但是紧接着我将ssh放入计算机以运行如下命令:
hosts: vcenter
gather_facts: false
tasks:
- name: Download GOVC
get_url:
url: https://github.com/vmware/govmomi/releases/download/v0.20.0/govc_linux_amd64.gz
dest: /home/gkeadmin/govc_linux_amd64.gz
但是在我得到以下信息后立即执行:fatal: [139.178.66.91]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 1.2.3.4 port 22: Operation timed out", "unreachable": true}
我再次使用--retry
命令重新运行它,然后继续。似乎只需要一段时间,我就可以通过ssh进行连接...如何等待在ansible中建立ssh的连接?
答案 0 :(得分:0)
ansible支持重试。可能会对您有帮助。
---
- name: test
retries: 2
hosts: <hosts_name>
tasks:
- name: task
<module_name>:
答案 1 :(得分:0)
例如,您可以在剧本的顶部添加一个部分来等待它,例如
---
- name: wait for ssh
tasks:
- wait_for:
port: 22
host: '{{ inventory_hostname }}'
delegate_to: localhost
- name: my playbook
hosts: vcenter
gather_facts: false
tasks:
- name: Download GOVC
[ ... etc ... ]
https://docs.ansible.com/ansible/latest/modules/wait_for_module.html#examples