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

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

问题描述

我正在尝试执行一个Ansible剧本,该剧本具有使用unarchive模块的任务.因为我在OSX上执行此操作,所以我需要它使用gnu-tar,而不是OSX通常随附的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二进制文件?对我来说,重写此行为以便使用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?

推荐答案

我已经找到了解决方案.

I've found the solution.

在继续之前,这是我的代码,用于确保冲煮安装的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变量与其他任何进程一样.但是,运行剧本会创建一个交互式非登录外壳.如此处所述,~/.bashrc文件将被加载用于交互式非登录外壳,而~/.bash_profile被加载用于登录外壳.

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文件中,因此无论我何时执行播放,它都不会执行.同样,这是因为进行播放会创建一个交互式非登录外壳,而不会加载~/.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天全站免登陆