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

vmware_deploy_ovf.py - AttributeError: 'NoneType' object has no attribute 'group' #1973

Open
MichaelHelmers opened this issue Jan 20, 2024 · 4 comments

Comments

@MichaelHelmers
Copy link

MichaelHelmers commented Jan 20, 2024

SUMMARY

AttributeError: 'NoneType' object has no attribute 'group'

I believe this is happening because the regex match in _parse_url of the class WebHandle does not allow for basic authentication credentials to be supplied in the url of the ofv template.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

vmware_deploy_ovf.py

ANSIBLE VERSION
ansible [core 2.16.2]
  config file = /home/ansible/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.11/site-packages/ansible
  ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.11.7 (main, Dec 19 2023, 03:30:20) [GCC 12.2.0] (/usr/local/bin/python)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /usr/local/lib/python3.11/site-packages/ansible_collections
Collection       Version
---------------- -------
community.vmware 4.0.1
CONFIGURATION
ANSIBLE_NOCOWS(/home/ansible/ansible.cfg) = True
1CACHE_PLUGIN(env: ANSIBLE_CACHE_PLUGIN) = jsonfile
1CACHE_PLUGIN_CONNECTION(env: ANSIBLE_CACHE_PLUGIN_CONNECTION) = /tmp/.ansible-runner-7_2msh53/artifacts/c1cd4051-9d6a-4564-9ca9-60bc2d3ffda0/fact_cache
1CALLBACKS_ENABLED(/home/ansible/ansible.cfg) = ['community.general.splunk']
1CONFIG_FILE() = /home/ansible/ansible.cfg
1DEFAULT_CALLBACK_PLUGIN_PATH(env: ANSIBLE_CALLBACK_PLUGINS) = ['/usr/local/lib/python3.11/site-packages/ansible_runner/display_callback/callback']
1DEFAULT_LOAD_CALLBACK_PLUGINS(/home/ansible/ansible.cfg) = True
1DEFAULT_NO_TARGET_SYSLOG(/home/ansible/ansible.cfg) = False
1DEFAULT_ROLES_PATH(/home/ansible/ansible.cfg) = ['/home/ansible/roles']
1DEFAULT_STDOUT_CALLBACK(env: ANSIBLE_STDOUT_CALLBACK) = awx_display
1DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /home/ansible/ansible-vault-secret.txt
1DISPLAY_SKIPPED_HOSTS(/home/ansible/ansible.cfg) = False
1HOST_KEY_CHECKING(env: ANSIBLE_HOST_KEY_CHECKING) = False
1INTERPRETER_PYTHON(/home/ansible/ansible.cfg) = python3
1RETRY_FILES_ENABLED(env: ANSIBLE_RETRY_FILES_ENABLED) = False
STEPS TO REPRODUCE

Set ofv_url to include basic auth credentials

ovf_url="https://admin:admin@myurl.com/path/to/ovf/template.ovf"

- name: "Deploy VM"
      community.vmware.vmware_deploy_ovf:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        cluster: "{{ cluster }}"
        datastore: "{{ datastore }}"
        datacenter: "{{ datacenter }}"
        name: "{{ vmname }}"
        networks: "{u'VM Network':u'{{ network_name }}'}"
        power_on: true
        url: "{{ ovf_url }}"
EXPECTED RESULTS

The regex should return a match.

ACTUAL RESULTS
servername failed: {
8a7fe7d1-4662-4705-9297-19fc0a390467-ansible-1  |     "changed": false,
8a7fe7d1-4662-4705-9297-19fc0a390467-ansible-1  |     "module_stderr": "/tmp/ansible_community.vmware.vmware_deploy_ovf_payload_drw3u_0i/ansible_community.vmware.vmware_deploy_ovf_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_deploy_ovf.py:289: FutureWarning: Possible nested set at position 138
Traceback (most recent call last):
  File \"/home/ansible/.ansible/tmp/ansible-tmp-1705724010.0562537-253-12111306265720/AnsiballZ_vmware_deploy_ovf.py\", line 107, in <module>
    _ansiballz_main()
  File \"/home/ansible/.ansible/tmp/ansible-tmp-1705724010.0562537-253-12111306265720/AnsiballZ_vmware_deploy_ovf.py\", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File \"/home/ansible/.ansible/tmp/ansible-tmp-1705724010.0562537-253-12111306265720/AnsiballZ_vmware_deploy_ovf.py\", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_deploy_ovf', init_globals=dict(_module_fqn='ansible_collections.community.vmware.plugins.modules.vmware_deploy_ovf', _modlib_path=modlib_path),
  File \"<frozen runpy>\", line 226, in run_module
  File \"<frozen runpy>\", line 98, in _run_module_code
  File \"<frozen runpy>\", line 88, in _run_code
  File \"/tmp/ansible_community.vmware.vmware_deploy_ovf_payload_drw3u_0i/ansible_community.vmware.vmware_deploy_ovf_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_deploy_ovf.py\", line 927, in <module>
  File \"/tmp/ansible_community.vmware.vmware_deploy_ovf_payload_drw3u_0i/ansible_community.vmware.vmware_deploy_ovf_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_deploy_ovf.py\", line 915, in main
  File \"/tmp/ansible_community.vmware.vmware_deploy_ovf_payload_drw3u_0i/ansible_community.vmware.vmware_deploy_ovf_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_deploy_ovf.py\", line 672, in upload
  File \"/tmp/ansible_community.vmware.vmware_deploy_ovf_payload_drw3u_0i/ansible_community.vmware.vmware_deploy_ovf_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_deploy_ovf.py\", line 596, in get_lease
  File \"/tmp/ansible_community.vmware.vmware_deploy_ovf_payload_drw3u_0i/ansible_community.vmware.vmware_deploy_ovf_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_deploy_ovf.py\", line 554, in get_ovf_descriptor
  File \"/tmp/ansible_community.vmware.vmware_deploy_ovf_payload_drw3u_0i/ansible_community.vmware.vmware_deploy_ovf_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_deploy_ovf.py\", line 263, in __init__
AttributeError: 'NoneType' object has no attribute 'group'
",
8a7fe7d1-4662-4705-9297-19fc0a390467-ansible-1  |     "module_stdout": "",
8a7fe7d1-4662-4705-9297-19fc0a390467-ansible-1  |     "msg": "MODULE FAILURE
See stdout/stderr for the exact error",
8a7fe7d1-4662-4705-9297-19fc0a390467-ansible-1  |     "rc": 1
8a7fe7d1-4662-4705-9297-19fc0a390467-ansible-1  | }
@MichaelHelmers
Copy link
Author

MichaelHelmers commented Jan 20, 2024

Maybe the regex could look something like this? I'm not very good with regex so sorry if this is incorrect/ignorant.

HTTP_SCHEMA_PATTERN = (
    r"(?P<url>(?:"
    r"(?P<scheme>[a-zA-Z]+:\/\/)?"
    r"(?P<auth>(?:(?P<username>[-a-zA-Z0-9!$&'()*+,\\\/;=\[\]._~]*:)?(?P<password>[-a-zA-Z0-9!$&'()*+,\\\/;=\[\]._~]*)))?"
    r"(?P<hostname>(?:[-a-zA-Z0-9@%_\+~#=]{1,256}\.){1,256}(?:[-a-zA-Z0-9@%_\+~#=]{1,256})))"
    r"(?::(?P<port>[[:digit:]]+))?"
    r"(?P<path>(?:\/[-a-zA-Z0-9!$&'()*+,\\\/:;=@\[\]._~%]*)*)"
    r"(?P<query>(?:(?:\#|\?)[-a-zA-Z0-9!$&'()*+,\\\/:;=@\[\]._~]*)*))"
)

I have tested out the change here [https://regex101.com/r/gE4aXA/2] and I've also coded up a python example which seems to match successfully

>>> def parse_url(url):
...     HTTP_SCHEMA_PATTERN = (
...         r"(?P<url>(?:"
...         r"(?P<scheme>[a-zA-Z]+:\/\/)?"
...         r"(?P<auth>(?:(?P<username>[-a-zA-Z0-9!$&'()*+,\\\/;=\[\]._~]*:)?(?P<password>[-a-zA-Z0-9!$&'()*+,\\\/;=\[\]._~]*)))?"
...         r"(?P<hostname>(?:[-a-zA-Z0-9@%_\+~#=]{1,256}\.){1,256}(?:[-a-zA-Z0-9@%_\+~#=]{1,256})))"
...         r"(?::(?P<port>[[:digit:]]+))?"
...         r"(?P<path>(?:\/[-a-zA-Z0-9!$&'()*+,\\\/:;=@\[\]._~%]*)*)"
...         r"(?P<query>(?:(?:\#|\?)[-a-zA-Z0-9!$&'()*+,\\\/:;=@\[\]._~]*)*)?)"
...     )
...     mymatch = re.match(HTTP_SCHEMA_PATTERN, url)
...     print(mymatch.group(1))
...     print(mymatch.group('scheme'))
...     return mymatch
... 
>>> parse_url("https://admin:admin@myurl.com/path/template.ovf?key1=val1")
https://admin:admin@myurl.com/path/template.ovf?key1=val1
https://
<re.Match object; span=(0, 57), match='https://admin:admin@myurl.com/path/template.ovf?k>

@ihumster
Copy link
Collaborator

@MichaelHelmers this module version is unsupported. Please reproduce issue on supported version of community.vmware (4.x and 3.x).

@MichaelHelmers
Copy link
Author

MichaelHelmers commented Jan 20, 2024

@MichaelHelmers this module version is unsupported. Please reproduce issue on supported version of community.vmware (4.x and 3.x).

@ihumster
Sorry I was tired last night and grabbed the version from the wrong place, grabbing the version from the container returns 4.0.1, edited the originating post to reflect this.

# /usr/local/lib/python3.11/site-packages/ansible_collections
Collection       Version
---------------- -------
community.vmware 4.0.1

The issue is still present.

@ihumster
Copy link
Collaborator

@MichaelHelmers Your regex doesn't work well with url without basic auth. =( I’ll think about it, plus I need to make it work with Basic Auth, now there is no authorization in the code at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants