ansible 的 unarchive 模块如何查找 tar 二进制文件? [英] How does ansible's unarchive module look for the tar binary?

查看:25
本文介绍了ansible 的 unarchive 模块如何查找 tar 二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行一个具有使用 unarchive 模块的任务的 ansible playbook.因为我在 OSX 上这样做,所以我需要它使用 gnu-tar,而不是 OSX 通常附带的 bsd tar,因为 BSD tar 不受官方支持.

I'm trying to execute an ansible playbook that has a task utilizing the unarchive module. Because I'm doing this on OSX, I need it to use gnu-tar, instead of the bsd tar that typically comes with OSX, since BSD tar is not officially supported.

我已经使用 brew 安装了 gnu-tar,并将这个包的 gnubin 文件夹放在 $ 中其他路径的前面PATH 变量.但是,我的剧本仍然在/usr/bin文件夹(原始tar的位置)中寻找tar,而不是新安装的gnu-tar.

I've installed gnu-tar using brew, and placed this package's gnubin folder ahead of other paths in the $PATH variable. However, my playbook still looks for tar in the /usr/bin folder (the location of the original tar), instead of the newly installed gnu-tar.

我的问题是,unarchive 模块如何查找 tar 二进制文件,以及我覆盖此行为以便它利用 tar 的最佳方法是什么?代码>gnu-tar,而不是?

My question is, how does the unarchive module look for the tar binary, and what would be the best way for me to override this behavior so that it utilizes gnu-tar, instead?

推荐答案

我找到了解决方案.

在我们继续之前,这是我的代码,用于确保 brew 安装的 gnu-tar 优先于 OSX 附带的 bsd-tar:

Before we proceed, this is my code for making sure that the brew-installed gnu-tar takes precedence over the bsd-tar that comes with OSX:

# gnu-tar
export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH"
export MANPATH="/usr/local/opt/gnu-tar/libexec/gnuman:$MANPATH"

此代码最初位于我的 ~/.bash_profile 文件中.

This code was originally located in my ~/.bash_profile file.

ansible 查找 tar 二进制文件的方式正如您所期望的:$PATH 变量,就像任何其他进程一样.但是,运行 play 会创建一个交互式非登录 shell.正如此处所述,~/.bashrc 文件被加载用于交互式非登录 shells,而 ~/.bash_profile登录 shells 加载.

The way that ansible looks up the tar binary is as you'd expect: the $PATH variable, like any other process. However, running a play creates an interactive non-login shell. As explained here, the ~/.bashrc file gets loaded for interactive non-login shells, while ~/.bash_profile gets loaded for login shells.

由于我的代码位于 ~/.bash_profile 文件中,所以每当我运行游戏时它都不会执行.同样,这是因为运行 play 会创建一个 交互式非登录 shell,它不会加载 ~/.bash_profile.因此,代码实际上应该在 ~/.bashrc 中.

Since my code was located in the ~/.bash_profile file, it never executes whenever I run a play. Again, this is because running a play creates an interactive non-login shell that does not load ~/.bash_profile. Hence, the code should actually be in ~/.bashrc.

确实,当我将代码移至 ~/.bashrc 时,我的任务开始使用已安装的 gnu-tar.我能够通过创建一个任务来确认这一点,将 which tar 注册到一个变量中并将其打印在另一个 debug 任务中.

True enough, the moment I moved my code to the ~/.bashrc was when my task started using the installed gnu-tar. I was able to confirm this by creating a task to register which tar into a variable and printing it in another debug task.

这篇关于ansible 的 unarchive 模块如何查找 tar 二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆