Repository: ansible/ansible-modules-core

Issue:
unarchive failed to transfer on devel
<!--- Verify first that your issue/request is not already reported in GitHub -->
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Bug Report
##### COMPONENT NAME

<!--- Name of the plugin/module/task -->

unarchive
##### ANSIBLE VERSION

<!--- Paste verbatim output from “ansible --version” between quotes below -->

ansible 2.2.0 (devel 134d70e7b9) last updated 2016/07/18 12:43:12 (GMT +1000)
  lib/ansible/modules/core: (detached HEAD 7de287237f) last updated 2016/07/18 12:43:16 (GMT +1000)
  lib/ansible/modules/extras: (detached HEAD 68ca157f3b) last updated 2016/07/18 12:43:16 (GMT +1000)
  config file = /home/linus/Documents/ansible-playbooks/ansible.cfg
  configured module search path = Default w/o overrides
##### CONFIGURATION

<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
hostfile = ./inventory
remote_user = centos
host_key_checking = False
log_path = /var/log/ansible.log
##### OS / ENVIRONMENT

<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->

management node: ubuntu 14.04
remote node: centos 7
##### SUMMARY

<!--- Explain the problem briefly -->

unarchive module shows error when src is an url using latest Ansible devel but works fine using the same playbook using Ansible stable 2.1.0.0 version.
##### STEPS TO REPRODUCE

<!---
For bugs, show exactly how to reproduce the problem.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->

```
unarchive:
    copy: no
    src: https://someurl.tar.gz
    dest: /tmp/somefolder
    owner: user
    group: user

```

<!--- You can also paste gist.github.com links for larger files -->
##### EXPECTED RESULTS

<!--- What did you expect to happen when running the steps above? -->

changed
##### ACTUAL RESULTS

<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

fatal: [xx.xx.xx.xx]: FAILED! => {"changed": false, "failed": true, "msg": "Source 'https://someurl.tar.gz' failed to transfer"}

<!--- Paste verbatim command output between quotes below -->



Discussion:
Found where the problem is: files/unarchive.py (Line 736):

> ```
>  if not os.path.exists(src):
>     if not remote_src or copy:
>         module.fail_json(msg="Source '%s' failed to transfer" % src)
> ```

Copy is set as always True. When you reach this condition, as copy will be always True, the module will fail everytime.  I think the correct is this:

> ```
> if not os.path.exists(src):
>     if not remote_src and copy:
>         module.fail_json(msg="Source '%s' failed to transfer" % src)
> ```

Can't push the correction now...maybe later. Sorry =/


Resolving patch:
diff --git a/files/unarchive.py b/files/unarchive.py
--- a/files/unarchive.py
+++ b/files/unarchive.py
@@ -734,7 +734,7 @@ def main():
     file_args = module.load_file_common_arguments(module.params)
     # did tar file arrive?
     if not os.path.exists(src):
-        if not remote_src or copy:
+        if not remote_src and copy:
             module.fail_json(msg="Source '%s' failed to transfer" % src)
         # If copy=false, and src= contains ://, try and download the file to a temp directory.
         elif '://' in src:


Test patch: