Unarchive module verbosity

Hello everyone!

I’ve got a problem with “unarchive” core module. With the latest version 1.9 the behavior of the module changed.

In ansible version 1.7.2 all gzip and tar archives were extracted with
tar (or gtar) command that had “-v” (–verbose) argument.

here is the piece of code from 1.7.2 version module (from class that handles gzip)

cmd = ‘%s -v -C “%s” --diff -%sf “%s”’ % (self.cmd_path, self.dest, self.zipflag, self.src)

and here is the same one from 1.9

cmd = ‘%s -C “%s” --diff -%sf “%s”’ % (self.cmd_path, self.dest, self.zipflag, self.src)

This affects the json output, especially the “out” section

“unarchived”: {
“changed”: false,
“msg”: “All items completed”,
“results”: [
{
“changed”: false,
“check_results”: {
“cmd”: “/bin/gtar -C "/app/tools" --diff -zf "/app/downloads/jdk-8.20.tar.gz"”,
“err”: “”,
“out”: “”,
“rc”: 0,
“unarchived”: true
},

In version 1.7.2 (with verbose flag) the “out” section contained all the files extracted, concatenated in one string.
This was really helpful when I need to create a symlink to the contents extracted.

Let me give you a bit more details. For example I have an archive of Java SDK.
The name of archive differs from the folder name that is inside of this archive. I need to create a symlink “/opt/java” (where my applications look for java) that point to the extracted contents.

So I used the following ansible code:

  • name: Unarchive Java
    tags:

  • java_install
    unarchive:
    src={{ item.dest }}
    dest={{ tools_dir }}
    copy=no
    register: unarchived
    with_items:

  • “{{ artifacts }}”

  • name: Create symlink for Java
    tags:

  • java_install
    file:
    state=link
    src={{ tools_dir }}/{{ unarchived.results[0].check_results.out.split(‘\n’)****[0].rstrip(‘/’) }}
    dest={{ java_dir }}

In this way i determined what folder names was inside the archive, so I was able to create a symlink.

With a newer version I can’t do this. So the questions are the following:

  1. Can I pass some kind of argument in ansible code to use verbose output?
  2. Is there any other way to determine the name of the folder inside of the archive using ansible? ( I could possibly miss something )
  3. Will this beavior be fixed/changed/modified?

Currently as a workaround I had to manually add “-v” argument to the module, but that would be really nice to have an option in a module so I can choose verbosity in ansible code.

I'll look into adding this back in today. I think I removed it since
we're screenscraping the output of tar here and using -v seemed like
it might interfere with getting the data we needed. If it turns out
that was just worrying for nothing I'll restore the -v flag.

-Toshio

Could you make it an option? I’d rather NOT see the huge mess on screen and in logs when the information is not needed.

I am totally agree with Jesse. An option would be the best of both solutions, flexible and nice.

Done. https://github.com/ansible/ansible-modules-core/commit/a19fa6ba48bf092b574eb6ee40f38f06500d767d

i implemented a list_files parameter for unarchive. If you specify
that, then in the return values you get a list of filenames via the
new files field. Use it like this:

$ ansible localhost -m unarchive -a 'src=/var/tmp/foo.tar.gz
dest=/var/tmp/unarchive list_files=True' -c local
localhost | success >> {
    "changed": false,
    "check_results": {
        "cmd": "/bin/gtar -C \"/var/tmp/unarchive\" --diff -zf
\"/root/.ansible/tmp/ansible-tmp-1429115525.59-235961690068875/source\"",
        "err": "",
        "out": "",
        "rc": 0,
        "unarchived": true
    },
    "dest": "/var/tmp/unarchive",
    "files": [
        "foo/",
        "foo/bar.txt"
    ],
    "gid": 1000,
    "group": "badger",
    "handler": "TgzArchive",
    "mode": "0755",
    "owner": "badger",
    "secontext": "unconfined_u:object_r:user_tmp_t:s0",
    "size": 4096,
    "src": "/root/.ansible/tmp/ansible-tmp-1429115525.59-235961690068875/source",
    "state": "directory",
    "uid": 1000
}

This is a little different than before (where it was all one string in
the "out" parameter but I think it's a little easier to use too. Hope
that works for you.

-Toshio

Cool! This is awesome!

Hi tkuratomi,

I just tested with version 1.9.2 and I get
“msg: unsupported parameter for module: list_files”

Did this change went into 1.9.2 version or it is still pending?

please disregard.

Found in docs (added in 2.0)