无法通过 macOS 中的 ansible unarchive 模块提取 tar 文件?
unable to extract tar file though ansible unarchive module in macOS?
我写了一个下载 tar 文件并将其解压缩到 Mac.But 中的某个目录的剧本,当我 运行 剧本失败并出现以下错误时
"msg": "Failed to find handler for \"/Users/harmeet/.ansible/tmp/ansible-tmp-1549339698.75-251687957122076/config.tar9IXAUQ.gz\". Make sure the required command to extract the file is installed. Command \"/usr/bin/tar\" detected as tar type bsd. GNU tar required. Command \"/usr/bin/unzip\" could not handle archive.
剧本代码
-name: Download the tar for sample config
unarchive:
src: http://someremoteurl/config.tar.gz
dest: /Users/{{ansible_user}}/.myfolder/
remote_src: yes
creates: /Users/{{ansible_user}}/.myfolder/config
如果在 http://someremoteurl/config.zip 等远程服务器上使用 zip fie,则此任务有效,但对于 tar 个文件,它会失败。
我还安装了 gnu tar,例如 gtar
并更新了 .bash_src
中的路径
实际上在 macOS 上它寻找基于 GNU 的 tar 存档模块,但在 mac 上找不到。因此,如果您在 ansible 中为 mac 使用 zip 模块,它会起作用,但为此我们可能需要更改 playbook 文件,它可能会产生问题,因为我对 mac 和 [=27 使用单个 playbook =].我使用基于 GNU 的 tar 归档模块来解决这个问题。
我通过以下步骤解决了这个问题
- 通过自制软件安装 gtar。
brew install gnu-tar
- 在
.bashsrc
文件中设置gtar的路径否则将无法使用gtar解压。通常 .bashsrc
存在于 $HOME
路径。如果不存在则创建它。
export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH"
export MANPATH="/usr/local/opt/gnu-tar/libexec/gnuman:$MANPATH"
谢谢
如果您的默认 shell 是 zsh
,那么您应该在 ~/.zshenv
中输入以下内容:
export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH"
您可以通过以下方式检查它是否正常工作:
ansible the-hostname -m command -a "which tar"
我写了一个下载 tar 文件并将其解压缩到 Mac.But 中的某个目录的剧本,当我 运行 剧本失败并出现以下错误时
"msg": "Failed to find handler for \"/Users/harmeet/.ansible/tmp/ansible-tmp-1549339698.75-251687957122076/config.tar9IXAUQ.gz\". Make sure the required command to extract the file is installed. Command \"/usr/bin/tar\" detected as tar type bsd. GNU tar required. Command \"/usr/bin/unzip\" could not handle archive.
剧本代码
-name: Download the tar for sample config
unarchive:
src: http://someremoteurl/config.tar.gz
dest: /Users/{{ansible_user}}/.myfolder/
remote_src: yes
creates: /Users/{{ansible_user}}/.myfolder/config
如果在 http://someremoteurl/config.zip 等远程服务器上使用 zip fie,则此任务有效,但对于 tar 个文件,它会失败。
我还安装了 gnu tar,例如 gtar
并更新了 .bash_src
中的路径
实际上在 macOS 上它寻找基于 GNU 的 tar 存档模块,但在 mac 上找不到。因此,如果您在 ansible 中为 mac 使用 zip 模块,它会起作用,但为此我们可能需要更改 playbook 文件,它可能会产生问题,因为我对 mac 和 [=27 使用单个 playbook =].我使用基于 GNU 的 tar 归档模块来解决这个问题。
我通过以下步骤解决了这个问题
- 通过自制软件安装 gtar。
brew install gnu-tar
- 在
.bashsrc
文件中设置gtar的路径否则将无法使用gtar解压。通常.bashsrc
存在于$HOME
路径。如果不存在则创建它。
export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH" export MANPATH="/usr/local/opt/gnu-tar/libexec/gnuman:$MANPATH"
谢谢
如果您的默认 shell 是 zsh
,那么您应该在 ~/.zshenv
中输入以下内容:
export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH"
您可以通过以下方式检查它是否正常工作:
ansible the-hostname -m command -a "which tar"