【问题标题】:Ansible Unarchive command causes error "Failed to find handler"Ansible Unarchive 命令导致错误“无法找到处理程序”
【发布时间】:2020-03-06 15:19:49
【问题描述】:

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

"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."

PlayBook的内容如下。

- name: Unarchive hoge
  become: yes
  unarchive:
    src: /tmp/hoge.db.gz
    dest: /root/fuga/
    remote_src: yes

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

  • 解压需要命令
[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"

【问题讨论】:

    标签: ansible


    【解决方案1】:

    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
    

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

    【讨论】:

    • 感谢您的回复。我没有正确阅读笔记。对不起。多亏了你,已经解决了。
    【解决方案2】:

    如果你像这样使用 extra_opts 就可以了:

    - name: Unarchive hoge
      become: true
      ansible.builtin.unarchive:
        src: /tmp/hoge.db.gz
        dest: /root/fuga/
        remote_src: yes
        extra_opts:
         - '-z'
    

    在 CentOS 8 上使用 ansible 2.9.25 和 python 3.6.8 进行测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-02
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      相关资源
      最近更新 更多