Ansible: error when trying to unarchive a .tar.gz retrieved via the “get_url” module

ansible

I'm using Ansible 1.9.4 on a Debian (Jessie 8.2) virtual machine.

I have a file that is stocked on Google Cloud Platform that I retrieve on the remote via the "get_url" module. But when I try to unzip it with gzip, I get an error saying :

gzip: stdin: not in gzip format

I can unarchive the file before uploading it or if I retrieve it via the graphic interface on the google developer console.

Do you have an idea of what could cause this ?

Best Answer

Instead of using gzip, try using tar with the gzip flag.

tar -zxvf myfile.tar.gz

z - using gzip compression
x - extract the archive
v - do it verbosely
f - use this file

The reason gzip will not work, is because what you actually have is a tarball, that is compressed using gzip, you can not just uncompress it, you need to extract the archive as well.

To create a .tar.gz file, you again use tar.

tar -zcvf output.tar.gz dir_to_zip/

Again, same flags as before, except this time you will use

c - compress

As opposed to x which extracts.