Ansible:如何为solaris全局设置PATH [英] Ansible: How to globally set PATH for solaris
问题描述
我正在编写Ansible手册,以在Solaris服务器上设置和安装我们的应用程序.
I am writing Ansible playbooks to setup and install our applications on Solaris servers.
问题是我需要执行的所有(bash)脚本都假设某个目录位于PATH上,即/data/bin
-如果不是Ansible忽略所有.bashrc
配置.
The problem is that the (bash) scripts which I need to execute all assume that a certain directory lies on the PATH, namely /data/bin
- which would normally not be a problem were it not for Ansible ignoring all the .profile
and .bashrc
config.
现在,我知道您可以通过environment
标志指定shell
任务的环境,例如:
Now, I know that you can specify the environment for shell
tasks via the environment
flag, for example like this:
- shell: printenv
environment:
PATH: /usr/bin:/usr/sbin:/data/bin
这将正确地放置/data/bin
文件夹的路径,并且printenv
命令将正确显示(否则我的bash脚本将正确运行).
This will properly path the /data/bin
folder, and the printenv
command will correctly display (or my bash scripts would correctly run).
但是.但是有两个问题:
- 首先,必须一遍又一遍地指定环境是很烦人的.我知道您可以在一些剧本基础文件变量及其引用中定义环境,但您 still 必须在每个
shell
任务上都设置environment: ...
. - 第二,上面的示例不允许我动态指定路径,例如as
PATH: $PATH:/data/bin
-因为Ansible以无法解析$PATH
的方式执行此操作,因此命令灾难性地失败.因此,从本质上讲,这将覆盖对PATH
的任何其他更改.
- First of all it is very annoying to have to specify the environment over and over again. I know that you can define the environment in some playbook base file variable and the reference that, but you still have to set
environment: ...
on every singleshell
task. - Secondly, the above example does not allow me to specify the path dynamically, e.g. as
PATH: $PATH:/data/bin
- because Ansible executes this in a way which does not resolve$PATH
, thus the command fails catastrophically. So essentially this will override any other changes toPATH
.
我正在寻找解决方案,
- 附加的
PATH
条目仅应一次 添加
- 附加的
PATH
条目不应覆盖其他任务添加的条目
- the additional
PATH
entry should only be added once - the additional
PATH
entry should not override entries added by other tasks
P.S.我在如何在Linux上做到这一点,但是它使用了Solaris上不存在的/etc/environment
. (/etc/profile
再次被Ansible忽略.)
P.S. I found this nice explanation on how to do this on Linux, but it makes use of /etc/environment
which does not exist on Solaris. (And /etc/profile
is once again ignored by Ansible.)
推荐答案
尝试在
这篇关于Ansible:如何为solaris全局设置PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!