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:
- Can I pass some kind of argument in ansible code to use verbose output?
- Is there any other way to determine the name of the folder inside of the archive using ansible? ( I could possibly miss something )
- 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.