Unarchive module verbosity

569 views
Skip to first unread message

Игорь Антонов

unread,
Apr 14, 2015, 8:06:23 AM4/14/15
to ansibl...@googlegroups.com
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.
 

Toshio Kuratomi

unread,
Apr 14, 2015, 10:29:04 AM4/14/15
to Игорь Антонов, ansible-devel
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
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-deve...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jesse Keating

unread,
Apr 14, 2015, 1:56:50 PM4/14/15
to ansible-devel
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.


- jlk

Игорь Антонов

unread,
Apr 15, 2015, 2:41:15 AM4/15/15
to ansibl...@googlegroups.com
I am totally agree with Jesse. An option would be the best of both solutions, flexible and nice.


вторник, 14 апреля 2015 г., 20:56:50 UTC+3 пользователь Jesse Keating написал:

Toshio Kuratomi

unread,
Apr 15, 2015, 12:33:52 PM4/15/15
to Игорь Антонов, ansible-devel
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

Игорь Антонов

unread,
Apr 19, 2015, 12:18:31 PM4/19/15
to ansibl...@googlegroups.com, ngort...@gmail.com
Cool! This is awesome!

среда, 15 апреля 2015 г., 19:33:52 UTC+3 пользователь tkuratomi написал:

Игорь Антонов

unread,
Jul 8, 2015, 3:26:17 AM7/8/15
to ansibl...@googlegroups.com, ngort...@gmail.com
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?


среда, 15 апреля 2015 г., 19:33:52 UTC+3 пользователь tkuratomi написал:

Игорь Антонов

unread,
Jul 8, 2015, 3:30:34 AM7/8/15
to ansibl...@googlegroups.com
please disregard.

Found in docs  (added in 2.0)

среда, 8 июля 2015 г., 10:26:17 UTC+3 пользователь Игорь Антонов написал:
Reply all
Reply to author
Forward
0 new messages