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

unarchive: unable to unpack tar.gz from URI with python3 interpreter #23591

Closed
pvdputte opened this issue Apr 13, 2017 · 9 comments · Fixed by #24732
Closed

unarchive: unable to unpack tar.gz from URI with python3 interpreter #23591

pvdputte opened this issue Apr 13, 2017 · 9 comments · Fixed by #24732
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. m:unarchive This issue/PR relates to the unarchive module. module This issue/PR relates to a module. python3

Comments

@pvdputte
Copy link

pvdputte commented Apr 13, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

unarchive

ANSIBLE VERSION
$ ansible --version
ansible 2.4.0 (devel 313591f8b8) last updated 2017/04/13 21:20:44 (GMT +200)
  config file = 
  configured module search path = [u'/home/pvdputte/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/pvdputte/VC/vendor/ansible-master/lib/ansible
  executable location = /home/pvdputte/VC/vendor/ansible-master/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
CONFIGURATION

Default

OS / ENVIRONMENT

Running from ubuntu 14.04LTS
Managing ubuntu 17.04 (only python 3 after base install)

SUMMARY

Attempting to run the unarchive task to download and extract an http URL yields an error "Source 'http://cdn01.downloads.smartbear.com/soapui/5.3.0/SoapUI-5.3.0-linux-bin.tar.gz' failed to transfer"

STEPS TO REPRODUCE
$ ansible-d targethost -e 'ansible_python_interpreter=/usr/bin/python3' -m unarchive -a "src=http://cdn01.downloads.smartbear.com/soapui/5.3.0/SoapUI-5.3.0-linux-bin.tar.gz dest=/tmp remote_src=true"
EXPECTED RESULTS

tar.gz file is fetched and extracted in the expected location. E.g. with python 2:

$ ansible-d targethost -m unarchive -a "src=http://cdn01.downloads.smartbear.com/soapui/5.3.0/SoapUI-5.3.0-linux-bin.tar.gz dest=/tmp remote_src=true"
targethost | SUCCESS => {
    "changed": true, 
    "dest": "/tmp", 
    "extract_results": {
        "cmd": [
            "/bin/tar", 
            "--extract", 
            "-C", 
            "/tmp", 
            "-z", 
            "-f", 
            "/tmp/ansible_3W9Kei/SoapUI-5.3.0-linux-bin.tar.gz"
        ], 
        "err": "", 
        "out": "", 
        "rc": 0
    }, 
    "gid": 0, 
    "group": "root", 
    "handler": "TgzArchive", 
    "mode": "01777", 
    "owner": "root", 
    "size": 4096, 
    "src": "/tmp/ansible_3W9Kei/SoapUI-5.3.0-linux-bin.tar.gz", 
    "state": "directory", 
    "uid": 0
}
ACTUAL RESULTS

ansible 2.3:

targethost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "attributes": null, 
            "backup": null, 
            "content": null, 
            "copy": true, 
            "creates": null, 
            "delimiter": null, 
            "dest": "/tmp", 
            "directory_mode": null, 
            "exclude": [], 
            "extra_opts": [], 
            "follow": false, 
            "force": null, 
            "group": null, 
            "keep_newer": false, 
            "list_files": false, 
            "mode": null, 
            "original_basename": "SoapUI-5.3.0-linux-bin.tar.gz", 
            "owner": null, 
            "regexp": null, 
            "remote_src": true, 
            "selevel": null, 
            "serole": null, 
            "setype": null, 
            "seuser": null, 
            "src": "http://cdn01.downloads.smartbear.com/soapui/5.3.0/SoapUI-5.3.0-linux-bin.tar.gz", 
            "unsafe_writes": null, 
            "validate_certs": true
        }
    }, 
    "msg": "Failure downloading http://cdn01.downloads.smartbear.com/soapui/5.3.0/SoapUI-5.3.0-linux-bin.tar.gz, write() argument must be str, not bytes"
}

ansible 2.4:

targethost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "attributes": null, 
            "backup": null, 
            "content": null, 
            "copy": true, 
            "creates": null, 
            "delimiter": null, 
            "dest": "/usr/local", 
            "directory_mode": null, 
            "exclude": [], 
            "extra_opts": [], 
            "follow": false, 
            "force": null, 
            "group": null, 
            "keep_newer": false, 
            "list_files": false, 
            "mode": null, 
            "original_basename": "SoapUI-5.3.0-linux-bin.tar.gz", 
            "owner": null, 
            "regexp": null, 
            "remote_src": false, 
            "selevel": null, 
            "serole": null, 
            "setype": null, 
            "seuser": null, 
            "src": "http://cdn01.downloads.smartbear.com/soapui/5.3.0/SoapUI-5.3.0-linux-bin.tar.gz", 
            "unsafe_writes": null, 
            "validate_certs": true
        }
    }, 
    "msg": "Source 'http://cdn01.downloads.smartbear.com/soapui/5.3.0/SoapUI-5.3.0-linux-bin.tar.gz' failed to transfer"
}

Using ansible + python 2 to download on the target system works fine.

At first I thought it would be similar to #19710, but apparently something related has already changed in master, as the 2.4 output looks different.

@ansibot
Copy link
Contributor

ansibot commented Apr 13, 2017

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. python3 labels Apr 13, 2017
@nitzmahone nitzmahone removed the needs_triage Needs a first human triage before being processed. label Apr 13, 2017
@maximede
Copy link
Contributor

I'm having the same issue ( with python 2.7 though) I think it's coming fromn the fact that remote_src is somehow set incorrectly.
If you look at the ansible 2.4 log, it says "remote_src": false,

@sivel
Copy link
Member

sivel commented May 16, 2017

This appears to be an inconsistency in the way that remote_src works in comparison to copy.

Specifically due to these lines:

    # did tar file arrive?
    if not os.path.exists(src):
        if not remote_src and copy:
            module.fail_json(msg="Source '%s' failed to transfer" % src)

The change that likely caused this is 6aeea1f

The work around currently is to also supply copy=false. The documentation lists that copy is deprecated in favor of remote_src but this code path will not allow you to use a URL, without setting copy=false

@maximede
Copy link
Contributor

maximede commented May 16, 2017

git bisect tells me that it hasn't been working since 7b197d8

probably because of this :

# remove action plugin only key
for key in ('remote_src', 'decrypt'):
    if key in new_module_args:
        del new_module_args[key]

in ansible/lib/ansible/plugins/action/unarchive.py

Using copy: false instead of remote_src: true worked for me

@sivel
Copy link
Member

sivel commented May 17, 2017

I've submitted a PR which should resolve the issue:

#24732

If possible, please test.

@jctanner
Copy link
Contributor

resolved_by_pr #24732

@pvdputte
Copy link
Author

I confirm that the issue is resolved. Great!

@maximede
Copy link
Contributor

@pvdputte not sure what the Ansible policy is, but, the PR is still not merged. I wouldn't consider this ticket closed until it's merged as it might confuse people or lead to the creation of dupes of this ticket

@pvdputte
Copy link
Author

Need sleep, sorry.

@pvdputte pvdputte reopened this May 18, 2017
abadger pushed a commit that referenced this issue May 23, 2017
@dagwieers dagwieers added the m:unarchive This issue/PR relates to the unarchive module. label Sep 27, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. m:unarchive This issue/PR relates to the unarchive module. module This issue/PR relates to a module. python3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants