unarchive module: creates does not work

1,357 views
Skip to first unread message

Olivier Javaux

unread,
Sep 14, 2014, 8:18:32 AM9/14/14
to ansible...@googlegroups.com
I am using ansible 1.8 devel

I have a task like this one:

- name: something
  unarchive: creates=some_file src=src_file.tar.gz dest=dest_dir

Archive is always copied, even if some_file exists
Browsing through source code, I saw that there is a runner/action_plugins/unarchive.py
file, which makes me think that there is an action named "unarchive".
In this file, there is no creates option.
Maybe some collision between action and module?

Please, could you explain me what is wrong?


Michael DeHaan

unread,
Sep 14, 2014, 9:29:16 AM9/14/14
to ansible...@googlegroups.com
I believe it may copy the file and only crack it open if it doesn't exist.

Regardless, please file a bug report with steps to reproduce so someone can take a look.

(Code-wise, if you want to take a look, this is dealt with lib/ansible/runner/action_plugins/unarchive.py -- the actual ansible module is only
the last bit of it)

Thanks!



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4b7ee8b1-949b-4bcc-a37e-1ca7c4f9017f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jon Hadfield

unread,
Sep 14, 2014, 2:23:16 PM9/14/14
to ansible...@googlegroups.com
I submitted a pull request to fix this issue: https://github.com/ansible/ansible/pull/8116
The reason is that the creates option is checked in /library/files/unarchive after it's already been copied in /lib/ansible/runner/action_plugins/unarchive.py.
Simply shifting the check to the action_plugin prevents an unnecessary file transfer. 

bry...@gmail.com

unread,
Dec 9, 2014, 4:52:27 PM12/9/14
to ansible...@googlegroups.com
Has this been addressed in 1.8.2? I am unable to get the creates parameter to work, and am wondering if I'm doing something wrong.

If I edit /usr/share/pyshared/ansible/runner/action_plugins/unarchive.py (ansible installed via PPA) and add

            print module_return.result

after lines

            module_return = self.runner._execute_module(conn, tmp, 'stat', module_args_tmp, inject=inject,
                                                        complex_args
=complex_args, persist_files=True)

it outputs

{u'msg': u'unsupported parameter for module: creates', u'failed': True}

which makes me think something is rather wrong.

Toshio Kuratomi

unread,
Dec 9, 2014, 8:10:30 PM12/9/14
to ansible...@googlegroups.com
The code seems to have gone in quite a while ago. It seems to work
for me and I'm not getting the same debugging output with 1.8.1 and
current devel.

I don't believe that there was anything in 1.8.2 that would be
different from both of those.

The fact that it's saying that creates unsupported when it's calling
the piece of hte module that run remotely implies to me that ansible
is finding an older module library on your system. Do you by chance
have an older checkout somewhere or an older distro package?

-Toshio
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/0bd2e93f-0f3e-4c9a-9d62-9148ab819351%40googlegroups.com.

bry...@gmail.com

unread,
Dec 10, 2014, 11:38:47 AM12/10/14
to ansible...@googlegroups.com
Thanks for the suggestion. But to my knowledge I don't have any other checkouts or packages installed. I even ran `sudo apt-get purge ansible`, and before I reinstalled I
  • verified that `find /usr/ -name '*ansible*'` output nothing
  • deleted /etc/ansible on the control machine
  • deleted ~/.ansible on both the control machine and the remote host

However I have the same result; when unarchive.py tries to stat the file I've passed as the creates parameter to unarchive, the stat fails as in my previous message.

bry...@gmail.com

unread,
Dec 10, 2014, 11:49:45 AM12/10/14
to ansible...@googlegroups.com
Pardon the reply to myself but I've stumbled upon a lead. If I use YAML module parameters, like

- unarchive:
    src
: 'file.zip'
    dest
: '/foo'
    creates
: '/foo/bar'

then the creates check never works, as described previously (the unarchive itself still works but it doesn't check for file existence so it always unarchives). But if instead I use key=value module parameters, like

- unarchive: src='file.zip' dest='/foo' creates='/foo/bar'

then it works fine. Bug?

Toshio Kuratomi

unread,
Dec 11, 2014, 1:51:46 AM12/11/14
to ansible...@googlegroups.com

Yeah, that would be a bug.  Probably best to open a bug report on github so we can look into it and not forget.

-Toshio

Capi Etheriel

unread,
Dec 18, 2014, 4:57:15 PM12/18/14
to ansible...@googlegroups.com
are you using variables in both complex syntax and inline syntax?
can you post the actual task where you use that module?
also, are you using copy=false?

bry...@gmail.com

unread,
Dec 18, 2014, 5:59:54 PM12/18/14
to ansible...@googlegroups.com
On Thursday, December 18, 2014 3:57:15 PM UTC-6, Capi Etheriel wrote:
are you using variables in both complex syntax and inline syntax?

Not sure I'm well enough versed in Ansible terminology to understand the question. If by variables in complex syntax you mean accessing nested data structures as in http://docs.ansible.com/playbooks_variables.html#accessing-complex-variable-data then no. But if that's not what you mean then hopefully the following answers your question anyway.
 
can you post the actual task where you use that module?

Sure, with some file names changed to protect the innocent. The following task (inside a custom role) works for me, respecting the creates parameter:
- name: extract project
  unarchive
: src='project-{{ project_version }}.zip' dest='/opt' creates='{{ project_dest }}/README.txt'
  sudo
: true

I also have a defaults/main.yml inside the role containing among other things the following:
---
project_version
: 1.2.3.v20141123
project_dest
: /opt/project-{{ project_version }}

Also files/project-1.2.3.v20141123.zip contains file project-1.2.3.v20141123/README.txt so if it gets unarchived to /opt as expected, the path given to the creates parameter should exist.

The following task unarchives but does not respect the creates parameter (so it always unarchives):
- name: extract project
  unarchive
:
    src
: 'project-{{ project_version }}.zip'
    dest
: '/opt'
    creates
: '{{ project_dest }}/README.txt'
  sudo
: true

also, are you using copy=false?

No.

Sorry I haven't yet opened a bug report on github. I can't upload my whole role and haven't gotten around to creating and verifying a minimal test case.
 
Reply all
Reply to author
Forward
0 new messages