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

uri module fails when url contains some IPv6 addresses #56258

Closed
crazzy opened this issue May 9, 2019 · 1 comment · Fixed by #56270
Closed

uri module fails when url contains some IPv6 addresses #56258

crazzy opened this issue May 9, 2019 · 1 comment · Fixed by #56270
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. net_tools Net-tools category python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.

Comments

@crazzy
Copy link

crazzy commented May 9, 2019

SUMMARY

With some IPv6 addresses the uri module (and probably others too) will fail with this error:

"msg": "invalid literal for int() with base 10: '16d8:0:7::205]:80'"

It doesn't fail with all IPv6 addresses, for example these works:
2a00:1450:400f:808::200e (ipv6.google.com)
2a03:2880:f10a:83:face:b00c::25de (facebook.com)

But this IPv6 address consistently fails: 2a00:16d8:0:7::205

In addition to version 2.7.10 mentioned below I've tested on 2.6.3 and 2.8.0a1.post0 as well with identical results.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

uri

ANSIBLE VERSION
ansible 2.7.10
  config file = /Users/jh/ansible.cfg
  configured module search path = ['/Users/jh/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.7.10/libexec/lib/python3.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.7.3 (default, Apr 10 2019, 13:56:56) [Clang 10.0.0 (clang-1000.11.45.5)]
CONFIGURATION
DEFAULT_REMOTE_USER(/Users/jh/.ansible.cfg) = jh
OS / ENVIRONMENT

I'm running Mac OS X Mojave (10.14) with ansible installed via homebrew (2.7.10) and pip in virtualenv for 2.8.0a1.post0.

STEPS TO REPRODUCE
ansible-playbook -vvv -i localhost, test.yml
---

- hosts: all
  become: no
  gather_facts: no
  tasks:
    - name: "Testing uri module with IPv6 address"
      delegate_to: localhost
      uri:
        method: GET
        return_content: no
        url: "http://[2a00:16d8:0:7::205]:80/"
        status_code:
          - 301
        follow_redirects: none
EXPECTED RESULTS

I would have expected the uri module to properly parse the IPv6 address and carry out the GET request, as would happen with for example any IPv4 address.

ACTUAL RESULTS

The module failed with the following error message which hints it failed to properly parse the URL:
"msg": "invalid literal for int() with base 10: '16d8:0:7::205]:80'"

ansible-playbook 2.7.10
  config file = /Users/jh/ansible.cfg
  configured module search path = ['/Users/jh/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.7.10/libexec/lib/python3.7/site-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.7.3 (default, Apr 10 2019, 13:56:56) [Clang 10.0.0 (clang-1000.11.45.5)]
Using /Users/jh/ansible.cfg as config file
Parsed localhost, inventory source with host_list plugin

PLAYBOOK: test.yml ***********************************************************************************
1 plays in test.yml

PLAY [all] *******************************************************************************************
META: ran handlers

TASK [Testing uri module with IPv6 address] **********************************************************
task path: /Users/jh/test.yml:7
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: jh
<localhost> EXEC /bin/sh -c 'echo ~jh && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/jh/.ansible/tmp/ansible-tmp-1557393092.490096-229627105081196 `" && echo ansible-tmp-1557393092.490096-229627105081196="` echo /Users/jh/.ansible/tmp/ansible-tmp-1557393092.490096-229627105081196 `" ) && sleep 0'
Using module file /usr/local/Cellar/ansible/2.7.10/libexec/lib/python3.7/site-packages/ansible/modules/net_tools/basics/uri.py
<localhost> PUT /Users/jh/.ansible/tmp/ansible-local-27644pz1f3dny/tmpa_c44d1a TO /Users/jh/.ansible/tmp/ansible-tmp-1557393092.490096-229627105081196/AnsiballZ_uri.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/jh/.ansible/tmp/ansible-tmp-1557393092.490096-229627105081196/ /Users/jh/.ansible/tmp/ansible-tmp-1557393092.490096-229627105081196/AnsiballZ_uri.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /Users/jh/.ansible/tmp/ansible-tmp-1557393092.490096-229627105081196/AnsiballZ_uri.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /Users/jh/.ansible/tmp/ansible-tmp-1557393092.490096-229627105081196/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
WARNING: The below traceback may *not* be related to the actual failure.
  File "/var/folders/_3/s3t9s9xj72bd84np_nnf6cqc0000gn/T/ansible_uri_payload_nKAzVY/ansible_uri_payload.zip/ansible/module_utils/urls.py", line 1259, in fetch_url
    client_key=client_key, cookies=cookies)
  File "/var/folders/_3/s3t9s9xj72bd84np_nnf6cqc0000gn/T/ansible_uri_payload_nKAzVY/ansible_uri_payload.zip/ansible/module_utils/urls.py", line 1162, in open_url
    client_cert=client_cert, client_key=client_key, cookies=cookies)
  File "/var/folders/_3/s3t9s9xj72bd84np_nnf6cqc0000gn/T/ansible_uri_payload_nKAzVY/ansible_uri_payload.zip/ansible/module_utils/urls.py", line 1070, in open
    r = urllib_request.urlopen(*urlopen_args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 469, in error
    result = self._call_chain(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 635, in http_error_302
    new = self.redirect_request(req, fp, code, msg, headers, newurl)
  File "/var/folders/_3/s3t9s9xj72bd84np_nnf6cqc0000gn/T/ansible_uri_payload_nKAzVY/ansible_uri_payload.zip/ansible/module_utils/urls.py", line 481, in redirect_request
    handler = maybe_add_ssl_handler(newurl, validate_certs)
  File "/var/folders/_3/s3t9s9xj72bd84np_nnf6cqc0000gn/T/ansible_uri_payload_nKAzVY/ansible_uri_payload.zip/ansible/module_utils/urls.py", line 816, in maybe_add_ssl_handler
    port = int(port)

fatal: [localhost -> localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "attributes": null,
            "backup": null,
            "body": null,
            "body_format": "raw",
            "client_cert": null,
            "client_key": null,
            "content": null,
            "creates": null,
            "delimiter": null,
            "dest": null,
            "directory_mode": null,
            "follow": false,
            "follow_redirects": "none",
            "force": false,
            "force_basic_auth": false,
            "group": null,
            "headers": {},
            "http_agent": "ansible-httpget",
            "method": "GET",
            "mode": null,
            "owner": null,
            "regexp": null,
            "remote_src": null,
            "removes": null,
            "return_content": false,
            "selevel": null,
            "serole": null,
            "setype": null,
            "seuser": null,
            "src": null,
            "status_code": [
                301
            ],
            "timeout": 30,
            "unsafe_writes": null,
            "url": "http://[2a00:16d8:0:7::205]:80/",
            "url_password": null,
            "url_username": null,
            "use_proxy": true,
            "validate_certs": true
        }
    },
    "msg": "invalid literal for int() with base 10: '16d8:0:7::205]:80'"
}
	to retry, use: --limit @/Users/jh/test.retry

PLAY RECAP *******************************************************************************************
localhost
@ansibot
Copy link
Contributor

ansibot commented May 9, 2019

Files identified in the description:

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

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. net_tools Net-tools category python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback. labels May 9, 2019
sivel added a commit to sivel/ansible that referenced this issue May 9, 2019
@sivel sivel added the has_pr This issue has an associated PR. label May 9, 2019
@jillr jillr removed the needs_triage Needs a first human triage before being processed. label May 16, 2019
@ansible ansible locked and limited conversation to collaborators Aug 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. net_tools Net-tools category python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants