Ansible Unarchive 命令导致错误“无法找到处理程序”

use*_*068 6 ansible

我使用 Ansible 在 EC2 上运行 AmazonLinux2。但是,当执行取消归档命令时,会显示以下错误。

"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."
Run Code Online (Sandbox Code Playgroud)

PlayBook的内容如下。

- name: Unarchive hoge
  become: yes
  unarchive:
    src: /tmp/hoge.db.gz
    dest: /root/fuga/
    remote_src: yes
Run Code Online (Sandbox Code Playgroud)

以下是我检查过的信息,以确定错误原因。

  • 取消存档需要命令
"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."
Run Code Online (Sandbox Code Playgroud)
  • 小路
- name: Unarchive hoge
  become: yes
  unarchive:
    src: /tmp/hoge.db.gz
    dest: /root/fuga/
    remote_src: yes
Run Code Online (Sandbox Code Playgroud)
"ansible_env.PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"
Run Code Online (Sandbox Code Playgroud)

Mat*_*t P 6

unarchive模块无法处理 gzip 文件,除非它们是压缩的 tar 球(请参阅https://docs.ansible.com/ansible/latest/modules/unarchive_module.html)。

您将需要使用该copy模块首先复制 gzip 文件,然后shell使用该模块将其解压缩gunzip

例子:

- copy:
    src: /tmp/hoge.db.gz
    dest: /root/fuga/hoge.db.gz
- shell: gunzip /root/fuga/hoge.db.gz
Run Code Online (Sandbox Code Playgroud)

您可能需要首先在托管主机上安装gunzip