Reputation: 173
I operate AmazonLinux2 on EC2 using Ansible. However, when the Unarchive command is executed, the following error is displayed.
"Failed to find handler for \"/tmp/hoge.db.gz\".
Make sure the required command to extract the file is installed.
Command \"/usr/bin/unzip\" could not handle archive. Command \"/usr/bin/gtar\" could not handle archive."
The contents of PlayBook are as follows.
- name: Unarchive hoge
become: yes
unarchive:
src: /tmp/hoge.db.gz
dest: /root/fuga/
remote_src: yes
Below is the information I have examined to identify the cause of the error.
[root@ip- ~]# which gtar
/usr/bin/gtar
[root@ip- ~]# which unzip
/usr/bin/unzip
[root@ip- ~]# which zipinfo
/usr/bin/zipinfo
- debug:
var: ansible_env.PATH
"ansible_env.PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"
Upvotes: 6
Views: 18076
Reputation: 11636
Make sure you are using gtar
to create the archive and not tar
.
I was creating my archive files on RHEL 7 with tar
and they worked fine with the unarchive
module.
When I migrated to RHEL 8 and used the same tar
script, I started getting this error. When I ran the same script with gtar
, it worked fine.
I debugged the ansible.modules.unarchive
module and behind the scenes, it runs this command:
gtar --list -C <dest> <src>
If that command returns error code 0, then it will work.
Upvotes: 0
Reputation: 686
Make sure your archive file is indeed an archive. In my case I thought I downloaded tar.gz file, yet it was a pure html file.
Example: https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.8.2/apache-zookeeper-3.8.2-bin.tar.gz
$ wget https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.8.2/apache-zookeeper-3.8.2-bin.tar.gz
$ file apache-zookeeper-3.8.2-bin.tar.gz: HTML document, ASCII text, with very long lines (785)
Upvotes: 0
Reputation: 166
It works if you use the extra_opts like so:
- name: Unarchive hoge
become: true
ansible.builtin.unarchive:
src: /tmp/hoge.db.gz
dest: /root/fuga/
remote_src: yes
extra_opts:
- '-z'
Tested with ansible 2.9.25 and python 3.6.8 on CentOS 8.
Upvotes: 2
Reputation: 2625
The unarchive
module cannot handle gzip files unless they are a compressed tar ball (see https://docs.ansible.com/ansible/latest/modules/unarchive_module.html).
You will need to use the copy
module to first copy the gzip file, and then the shell
module to decompress it using gunzip
.
Example:
- copy:
src: /tmp/hoge.db.gz
dest: /root/fuga/hoge.db.gz
- shell: gunzip /root/fuga/hoge.db.gz
You may need to first install gunzip on the managed host
Upvotes: 6