Ansible playbook 无法连接到来宾 VM。抛出异常 NewConnectionError
Ansible playbook fails to connect to a guest VM. Exception thrown NewConnectionError
我已经创建了一个剧本来在 vmware Vcenter 中创建 VM。它运作良好。我使用本地主机作为主机在此虚拟中心上创建虚拟机。现在,我正尝试在新创建的虚拟机上执行命令,但出现连接错误。我的 ansible 剧本显示的错误消息尝试从部署了新虚拟机的 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 主机
我可以知道为什么使用 vmware_vm_shell 模块吗?
如果VM上启用了SSH,你可以直接尝试shell module..
我已经创建了一个剧本来在 vmware Vcenter 中创建 VM。它运作良好。我使用本地主机作为主机在此虚拟中心上创建虚拟机。现在,我正尝试在新创建的虚拟机上执行命令,但出现连接错误。我的 ansible 剧本显示的错误消息尝试从部署了新虚拟机的 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 主机
我可以知道为什么使用 vmware_vm_shell 模块吗? 如果VM上启用了SSH,你可以直接尝试shell module..