Ansible: How to globally set PATH for solaris

心不动则不痛 提交于 2019-12-12 08:58:22

问题


I am writing Ansible playbooks to setup and install our applications on Solaris servers.

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.

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

This will properly path the /data/bin folder, and the printenv command will correctly display (or my bash scripts would correctly run).

But. There are two problems however:

  • 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 single shell 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 to PATH.

I am looking for a solution where

  • the additional PATH entry should only be added once
  • the additional PATH entry should not override entries added by other tasks

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


回答1:


try adding -o SendEnv=PATH to ssh_args in ansible.cfg. Requires that

  • the shell in which you run ansible has /data/bin in PATH. Or however ansible allows you to modify the current/local PATH variable.
  • remote machine has AcceptEnv set correctly.


来源:https://stackoverflow.com/questions/27817310/ansible-how-to-globally-set-path-for-solaris

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!