Ansible playbook 无法连接到来宾虚拟机。 NewConnectionError 抛出异常
我创建了一个剧本来在 vmware Vcenter 中创建虚拟机。效果很好。我已使用本地主机作为主机在此vcenter上创建虚拟机。现在,我尝试在新创建的虚拟机上执行命令,但收到连接错误。我的 ansible playbook 显示的错误消息尝试从部署新虚拟机的 ESX 主机登录。请帮我解决这个问题。 我的剧本:
---
- name : do opearation on vm
hosts : rhel66
vars_files :
- "playbook_vars.yml"
tasks :
- name : Run command inside a vm
vmware_vm_shell :
hostname: "{{ vcenter_name }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ vcenter_datacenter }}"
#folder: AutomationDevelopment/vm/Environments/Env07/rhel66_testvm
vm_id: "{{ vm_name }}"
validate_certs : false
vm_username: root
vm_password: *******
vm_shell: /bin/echo
vm_shell_args: " $var >> myFile "
vm_shell_env:
- "PATH=/bin"
- "VAR=test"
vm_shell_cwd: "/tmp"
register: shell_command_output
剧本输出:
____________________________
< PLAY [do opearation on vm] >
----------------------------
________________________
< TASK [Gathering Facts] >
------------------------|
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: requests.exceptions.ProxyError: HTTPSConnectionPool(host='YY.YY.YY.YY', port=443): Max retries exceeded with url: /guestFile?id=235&token=52009a00-3927-ee12-8e82-bb795a2332c5235 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f4d69e0c0f0>: Failed to establish a new connection: [Errno 113] No route to host',)))
fatal: [XX.XX.XX.XX]: FAILED! => {"msg": "Unexpected failure during module execution.", "stdout": ""}
____________
< PLAY RECAP >
------------
在上面的错误中:XX.XX.XX.XX ->我的新虚拟机 IP 和 YY.YY.YY.YY 是部署此新虚拟机的 ESX 主机
I have created a playbook to create VM in a vmware Vcenter. It worked fine. I have used my localhost as host to create a vm on this vcenter. Now, I am trying to execute a command on that newly created vm but I am getting a connection error. The error message shown by my ansible playbook tries to login from the ESX host on which the new vm is deployed. Please help me to resolve this.
my playbook:
---
- name : do opearation on vm
hosts : rhel66
vars_files :
- "playbook_vars.yml"
tasks :
- name : Run command inside a vm
vmware_vm_shell :
hostname: "{{ vcenter_name }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ vcenter_datacenter }}"
#folder: AutomationDevelopment/vm/Environments/Env07/rhel66_testvm
vm_id: "{{ vm_name }}"
validate_certs : false
vm_username: root
vm_password: *******
vm_shell: /bin/echo
vm_shell_args: " $var >> myFile "
vm_shell_env:
- "PATH=/bin"
- "VAR=test"
vm_shell_cwd: "/tmp"
register: shell_command_output
playbook output:
____________________________
< PLAY [do opearation on vm] >
----------------------------
________________________
< TASK [Gathering Facts] >
------------------------|
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: requests.exceptions.ProxyError: HTTPSConnectionPool(host='YY.YY.YY.YY', port=443): Max retries exceeded with url: /guestFile?id=235&token=52009a00-3927-ee12-8e82-bb795a2332c5235 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f4d69e0c0f0>: Failed to establish a new connection: [Errno 113] No route to host',)))
fatal: [XX.XX.XX.XX]: FAILED! => {"msg": "Unexpected failure during module execution.", "stdout": ""}
____________
< PLAY RECAP >
------------
In above error: XX.XX.XX.XX -> my new vm IP and YY.YY.YY.YY is my ESX host on which this new vm is deployed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

处理完这个问题并实际回答我自己的问题(因为这里没有答案而问),我认为你的问题是路由。没有到主机的路由。我最初不明白的是它正在尝试连接到虚拟机所在的主机,而不是vCenter。希望这有帮助。我将其用于 Windows VM,即连接插件,当尝试在 Windows 2016 VM 上安装 openssh 时,它很有帮助。当您需要在连接网络之前做一些事情时,它也很有帮助。
After dealing with this, and actually answering my own question (asked because there wasn't an answer here), I think your issue is routing. There is no route to host. What I didn't understand initially was that it is trying to connect to the host that the vm is resident on, not the vCenter. Hopefully that helps. I use this for Windows VM's, the connection plugin that is, and it is helpful when trying to install openssh on windows 2016 VMs. It is also helpful when you need to do things prior to connecting the network.