Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community.vmware.vmware_cfg_backup failing #1383

Closed
msilveirabr opened this issue Jul 7, 2022 · 10 comments · Fixed by #1392
Closed

community.vmware.vmware_cfg_backup failing #1383

msilveirabr opened this issue Jul 7, 2022 · 10 comments · Fixed by #1392
Labels
bug This issue/PR relates to a bug needs_triage Needs a first human triage before being processed. python3 traceback

Comments

@msilveirabr
Copy link
Contributor

msilveirabr commented Jul 7, 2022

SUMMARY

Mixed results using the cfg_backup module:
I have tried this module with different servers, and actually, I can only get it working on one ESXi host.
I tried to perform the backup on 2 fresh installs and other production servers without success.

HOSTS details:

Working hosts:

  • 6.7.0 Releasebuild-17167734 Update 3 patch 132

Non working hosts:

  • 6.5.0 Releasebuild-4564106 Update 0 Patch 0
  • 6.5.0 Releasebuild-14320405 Update 3 Patch 101 (official release 650U3A)
  • 6.7.0 Releasebuild-15160138 Update 3 Patch 89 (official release 670U3b)

This issue happens using ansible 2.9.27 and 2.12 too

Just wondering if I am doing something stupid. I'm going crazy trying to debug this.
PS: It doesn't matter if the dest file already exists or not.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.vmware.vmware_cfg_backup

ANSIBLE VERSION

Fedora FC33:

ansible 2.9.27
  config file = /home/mauricio.silveira/ansible/VMware/bl-esxi-cfg-backup/ansible.cfg
  configured module search path = ['/home/mauricio.silveira/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.9.9 (main, Nov 19 2021, 00:00:00) [GCC 10.3.1 20210422 (Red Hat 10.3.1-1)]

Rocky Linux 8.5:

ansible [core 2.12.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.12 (default, May 10 2022, 23:46:40) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)]
  jinja version = 2.10.3
  libyaml = True
COLLECTION VERSION

FC33: same versions as Rocky Linux ( ansible 2.9 has no list parameter )
Rocky Linux:

# /home/ansible/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 5.2.0  
community.vmware  2.6.0  
CONFIGURATION
DEFAULT_HOST_LIST(/home/ansible/VMware/single-esxcfgbkp/ansible.cfg) = ['/home/ansible/VMware/single-esxcfgbkp/inventory']
OS / ENVIRONMENT

Fedora FC33 (ansible 2.9.7) and Rocky Linux 8.5 (ansible 2.12)

STEPS TO REPRODUCE

ansible.cfg:

[defaults]
inventory = inventory

inventory:

[vmhost]
192.168.99.1
#192.168.99.2

[vmhost:vars]
ansible_user = root
ansible_python_interpreter = /bin/python3

simple_test.yml

# esxi_backup playbook
- name: ESXi hosts backup Playbook
  hosts: vmhost
  gather_facts: False
  tasks:

  - name: "Saving to /tmp/configBundle.tgz"
    community.vmware.vmware_cfg_backup:
      validate_certs: false
      hostname: "{{ inventory_hostname }}"
      username: root
      password: P@ssW0rd
      state: saved
      dest: "/tmp/configBundle.tgz"
    delegate_to: localhost
EXPECTED RESULTS

To work on any ESXi 6.x HOST

ACTUAL RESULTS

Only works on 1 host

Working host:

[ansible@ansible01 single-esxcfgbkp]$ ansible-playbook single_test.yml 

PLAY [ESXi hosts backup Playbook] ************************************************************************************************************************************************************************************************************

TASK [Saving to /tmp/configBundle.tgz] *******************************************************************************************************************************************************************************************************
changed: [192.168.99.1 -> localhost]

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
192.168.99.1              : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Non working hosts:

[ansible@ansible01 single-esxcfgbkp]$ ansible-playbook single_test.yml 

PLAY [ESXi hosts backup Playbook] ************************************************************************************************************************************************************************************************************

TASK [Saving to /tmp/configBundle.tgz] *******************************************************************************************************************************************************************************************************
fatal: [192.168.99.2 -> localhost]: FAILED! => {"changed": false, "msg": "Failed to write backup file. Ensure that the dest path exists and is writable. Details : <urlopen error [Errno -2] Name or service not known>"}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
192.168.99.2             : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Non working hosts verbose (-vvv) of "TASK [Saving to /tmp/configBundle.tgz]" :

The full traceback is:
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_qs0a508x/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py", line 185, in save_configuration
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_qs0a508x/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible/module_utils/urls.py", line 1384, in open_url
    return Request().open(method, url, data=data, headers=headers, use_proxy=use_proxy,
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_qs0a508x/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible/module_utils/urls.py", line 1294, in open
    r = urllib_request.urlopen(*urlopen_args)
  File "/usr/lib64/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python3.9/urllib/request.py", line 517, in open
    response = self._open(req, data)
  File "/usr/lib64/python3.9/urllib/request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib64/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_qs0a508x/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible/module_utils/urls.py", line 467, in https_open
    return self.do_open(self._build_https_connection, req)
  File "/usr/lib64/python3.9/urllib/request.py", line 1349, in do_open
    raise URLError(err)
fatal: [192.168.99.2 -> localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "dest": "/tmp/configBundle.tgz",
            "esxi_hostname": null,
            "hostname": "192.168.99.2",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "proxy_host": null,
            "proxy_port": null,
            "src": null,
            "state": "saved",
            "username": "root",
            "validate_certs": false
        }
    },
    "msg": "Failed to write backup file. Ensure that the dest path exists and is writable. Details : <urlopen error [Errno -2] Name or service not known>"
}

@ansibullbot
Copy link

Files identified in the description:
None

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot ansibullbot added bug This issue/PR relates to a bug needs_triage Needs a first human triage before being processed. python3 traceback labels Jul 7, 2022
@sky-joker
Copy link
Collaborator

Thanks, @msilveirabr for reporting the issue!

Details : <urlopen error [Errno -2] Name or service not known>

If I understand correctly, this error occurs when network reachability has not.
Can you reach a packet to the host with the ping command on the Ansible host?

@msilveirabr
Copy link
Contributor Author

msilveirabr commented Jul 7, 2022

Thanks, @msilveirabr for reporting the issue!

Details : <urlopen error [Errno -2] Name or service not known>

If I understand correctly, this error occurs when network reachability has not. Can you reach a packet to the host with the ping command on the Ansible host?

Hi, ansible -m ping all works as expected.

I have many community.vmware modules in use in other playbooks working fine... so far, this is the very first possible bug I've found in cfg_backup.

I tried playing around with DNS, A and PTR entries, matching the name to the hostname, etc...

I believe this should work on a fresh provisioned ( absolutely no configuratio done, just out of the box dhcp / SSH communication and keys setup ), right?

Since it is not happening on a production server, I'm available for patch testing.

@mariolenz
Copy link
Collaborator

@sky-joker I think the error message is not really helpful. Could you please review PR #1388? This should add some more information that might help troubleshoot issues with vmware_cfg_backup.

@msilveirabr
Copy link
Contributor Author

@sky-joker I think the error message is not really helpful. Could you please review PR #1388? This should add some more information that might help troubleshoot issues with vmware_cfg_backup.

Hi. Not sure if I should post this here or at #1388 ... here's the output:

TASK [Saving to /tmp/configBundle.tgz] ***************************************************************************************************************************************************************************************************************************************************************************************
task path: /home/msilveirabr/ansible/VMware/single-esxcfgbkp/single_test.yml:7
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: mauricio.silveira
<localhost> EXEC /bin/sh -c 'echo ~mauricio.silveira && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/msilveirabr/.ansible/tmp `"&& mkdir "` echo /home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412 `" && echo ansible-tmp-1657539992.0115025-1009452-175001000016412="` echo /home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412 `" ) && sleep 0'
Using module file /home/msilveirabr/.ansible/collections/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py
<localhost> PUT /home/msilveirabr/.ansible/tmp/ansible-local-1009445xv9h3m33/tmpu865bmrn TO /home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412/AnsiballZ_vmware_cfg_backup.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412/ /home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412/AnsiballZ_vmware_cfg_backup.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3 /home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412/AnsiballZ_vmware_cfg_backup.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/usr/lib64/python3.9/urllib/request.py", line 1346, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/usr/lib64/python3.9/http/client.py", line 1285, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib64/python3.9/http/client.py", line 1331, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib64/python3.9/http/client.py", line 1280, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib64/python3.9/http/client.py", line 1040, in _send_output
    self.send(msg)
  File "/usr/lib64/python3.9/http/client.py", line 980, in send
    self.connect()
  File "/usr/lib64/python3.9/http/client.py", line 1447, in connect
    super().connect()
  File "/usr/lib64/python3.9/http/client.py", line 946, in connect
    self.sock = self._create_connection(
  File "/usr/lib64/python3.9/socket.py", line 823, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib64/python3.9/socket.py", line 954, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py", line 185, in save_configuration
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible/module_utils/urls.py", line 1384, in open_url
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible/module_utils/urls.py", line 1294, in open
  File "/usr/lib64/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python3.9/urllib/request.py", line 517, in open
    response = self._open(req, data)
  File "/usr/lib64/python3.9/urllib/request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib64/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible/module_utils/urls.py", line 467, in https_open
  File "/usr/lib64/python3.9/urllib/request.py", line 1349, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412/AnsiballZ_vmware_cfg_backup.py", line 102, in <module>
    _ansiballz_main()
  File "/home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412/AnsiballZ_vmware_cfg_backup.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412/AnsiballZ_vmware_cfg_backup.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_cfg_backup', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib64/python3.9/runpy.py", line 210, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib64/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py", line 230, in <module>
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py", line 226, in main
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py", line 124, in process_state
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py", line 190, in save_configuration
TypeError: not all arguments converted during string formatting
fatal: [192.168.99.1 -> localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/usr/lib64/python3.9/urllib/request.py\", line 1346, in do_open\n    h.request(req.get_method(), req.selector, req.data, headers,\n  File \"/usr/lib64/python3.9/http/client.py\", line 1285, in request\n    self._send_request(method, url, body, headers, encode_chunked)\n  File \"/usr/lib64/python3.9/http/client.py\", line 1331, in _send_request\n    self.endheaders(body, encode_chunked=encode_chunked)\n  File \"/usr/lib64/python3.9/http/client.py\", line 1280, in endheaders\n    self._send_output(message_body, encode_chunked=encode_chunked)\n  File \"/usr/lib64/python3.9/http/client.py\", line 1040, in _send_output\n    self.send(msg)\n  File \"/usr/lib64/python3.9/http/client.py\", line 980, in send\n    self.connect()\n  File \"/usr/lib64/python3.9/http/client.py\", line 1447, in connect\n    super().connect()\n  File \"/usr/lib64/python3.9/http/client.py\", line 946, in connect\n    self.sock = self._create_connection(\n  File \"/usr/lib64/python3.9/socket.py\", line 823, in create_connection\n    for res in getaddrinfo(host, port, 0, SOCK_STREAM):\n  File \"/usr/lib64/python3.9/socket.py\", line 954, in getaddrinfo\n    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):\nsocket.gaierror: [Errno -2] Name or service not known\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py\", line 185, in save_configuration\n  File \"/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible/module_utils/urls.py\", line 1384, in open_url\n  File \"/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible/module_utils/urls.py\", line 1294, in open\n  File \"/usr/lib64/python3.9/urllib/request.py\", line 214, in urlopen\n    return opener.open(url, data, timeout)\n  File \"/usr/lib64/python3.9/urllib/request.py\", line 517, in open\n    response = self._open(req, data)\n  File \"/usr/lib64/python3.9/urllib/request.py\", line 534, in _open\n    result = self._call_chain(self.handle_open, protocol, protocol +\n  File \"/usr/lib64/python3.9/urllib/request.py\", line 494, in _call_chain\n    result = func(*args)\n  File \"/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible/module_utils/urls.py\", line 467, in https_open\n  File \"/usr/lib64/python3.9/urllib/request.py\", line 1349, in do_open\n    raise URLError(err)\nurllib.error.URLError: <urlopen error [Errno -2] Name or service not known>\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412/AnsiballZ_vmware_cfg_backup.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412/AnsiballZ_vmware_cfg_backup.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/msilveirabr/.ansible/tmp/ansible-tmp-1657539992.0115025-1009452-175001000016412/AnsiballZ_vmware_cfg_backup.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_cfg_backup', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib64/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py\", line 230, in <module>\n  File \"/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py\", line 226, in main\n  File \"/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py\", line 124, in process_state\n  File \"/tmp/ansible_community.vmware.vmware_cfg_backup_payload_4lgjz6z7/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py\", line 190, in save_configuration\nTypeError: not all arguments converted during string formatting\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP *******************************************************************************************************************************************************************************************************************************************************************************************************************
192.168.99.1             : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

@mariolenz
Copy link
Collaborator

@msilveirabr Your last comment looks like you've tested the code from my PR. Unfortunately, I don't see what argument caused the TypeError: not all arguments converted during string formatting error.

I've updated my PR to build the error message in three steps. This should help to identify the problematic argument.

softwarefactory-project-zuul bot pushed a commit that referenced this issue Jul 12, 2022
vmware_cfg_backup: Improve error message

SUMMARY
We've had two issues with vmware_cfg_backup recently and I think the error message could be improved to help us troubleshoot.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
vmware_cfg_backup
ADDITIONAL INFORMATION
#1270 and #1383

Reviewed-by: sky-joker <[email protected]>
@msilveirabr
Copy link
Contributor Author

@msilveirabr Your last comment looks like you've tested the code from my PR. Unfortunately, I don't see what argument caused the TypeError: not all arguments converted during string formatting error.

I've updated my PR to build the error message in three steps. This should help to identify the problematic argument.

The updated PR allowed me to narrow down the issue:

The full traceback is:
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_lrjhw0jg/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_cfg_backup.py", line 185, in save_configuration
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_lrjhw0jg/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible/module_utils/urls.py", line 1384, in open_url
    return Request().open(method, url, data=data, headers=headers, use_proxy=use_proxy,
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_lrjhw0jg/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible/module_utils/urls.py", line 1294, in open
    r = urllib_request.urlopen(*urlopen_args)
  File "/usr/lib64/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python3.9/urllib/request.py", line 517, in open
    response = self._open(req, data)
  File "/usr/lib64/python3.9/urllib/request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib64/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/tmp/ansible_community.vmware.vmware_cfg_backup_payload_lrjhw0jg/ansible_community.vmware.vmware_cfg_backup_payload.zip/ansible/module_utils/urls.py", line 467, in https_open
    return self.do_open(self._build_https_connection, req)
  File "/usr/lib64/python3.9/urllib/request.py", line 1349, in do_open
    raise URLError(err)
fatal: [192.168.99.1 -> localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "dest": "/tmp/configBundle.tgz",
            "esxi_hostname": null,
            "hostname": "192.168.99.1",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "proxy_host": null,
            "proxy_port": null,
            "src": null,
            "state": "saved",
            "username": "root",
            "validate_certs": false
        }
    },
    "msg": "Failed to save https://localhost.ad.mydomain.com.br/downloads/52de1e28-fc44-7eb4-7922-9d9df6e2f532/configBundle-localhost.ad.mydomain.com.br.tgz to /tmp/configBundle.tgz. Ensure that the dest path exists and is writable. Details: <urlopen error [Errno -2] Name or service not known>"
}

Some part of the code seems to get the FQDN from the ESXi host to assemble the URL to download the backup file.

It looks like the whole process is tied to getting the ESXi host FQDN, according to the code:

    def find_host_system(self):
        if self.esxi_hostname:
            host_system_obj = self.find_hostsystem_by_name(host_name=self.esxi_hostname)
            if host_system_obj:
                return host_system_obj
            else:
                self.module.fail_json(msg="Failed to find ESXi %s" % self.esxi_hostname)

        host_system = get_all_objs(self.content, [vim.HostSystem])
        return list(host_system)[0]

After some testing, I got to this conclusion:

When esxi_hostname is set, and hostname is a vcenter appliance, the esxi_hostname must be the host name in the vCenter inventory, not necessarily its DNS name -> eg: I added a second host to my test vCenter using the host's IP address, added both A and PTR DNS entries to the domain, then changed the playbook using the FQDN as esxi_hostname. The backup failed using FQDN, but succeeded using IP address as esxi_hostname.

When esxi_hostname is not set, and hostname is an ESXi host, esxi_hostname must match the ESXi host configured FQDN and the FQDN must be correctly configured, FQDN must resolve at the ansible host running the playbook.

According to the save/restore code, it makes no sense on relying on vim.HostSystem[0].name on a standalone host.

I'll open a PR with a proposed fix/improvement.

@mariolenz
Copy link
Collaborator

The module tries to discover the download URL. But when connecting directly to an ESXi host, it answers with something like https://*/downloads/52de1e28-fc44-7eb4-7922-9d9df6e2f532/configBundle-localhost.ad.mydomain.com.br.tgz. That's why the module substitutes * with the hostname that the ESXi host is configured with:

url = url.replace('*', self.host.name)

Maybe it would be better to use the hostname parameter from the playbook / module. We know that this works, otherwise the module would have failed earlier ;-)

I didn't test this yet, but maybe changing the above line to

        url = url.replace('*', self.esxi_hostname)

helps. That is, if you're connecting directly to an ESXi host. I'm not sure what happens if you connect to a vCenter, I'll have to test this.

@sky-joker Thoughts?

@sky-joker
Copy link
Collaborator

@mariolenz
I think it has not a problem to use esxi_hostname :-)

@mariolenz
Copy link
Collaborator

@sky-joker

I think it has not a problem to use esxi_hostname :-)

I don't think so, either. I've quickly added some simple integration tests for vmware_cfg_backup (#1389 and #1394) and the proposed fix doesn't fail them :-)

If you're interested, what do you think about PR #1392? Seems like a good fix to me.

@mariolenz mariolenz linked a pull request Jul 24, 2022 that will close this issue
@mariolenz mariolenz linked a pull request Jul 24, 2022 that will close this issue
softwarefactory-project-zuul bot pushed a commit that referenced this issue Jul 24, 2022
Proposed fixes for backup behavior #1383

Depends-On: ansible/ansible-zuul-jobs#1591
SUMMARY

Proposed fix for Issue #1383 following PR #1388

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

vmware_cfg_backup
ADDITIONAL INFORMATION


Check if hostname is an ESXi host or a vCenter appliance, discard esxi_hostname if target is an ESXi host.

Reviewed-by: Mario Lenz <[email protected]>
Reviewed-by: sky-joker <[email protected]>
Reviewed-by: Mauricio Silveira <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug needs_triage Needs a first human triage before being processed. python3 traceback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants