Ansible,从 playbook 加载 /etc/profile
Ansible, load /etc/profile from playbook
我尝试重新加载位于 /etc/profile 的 bash 配置文件时遇到问题。
我尝试通过多种方式加载它,从
命令:. /etc/profile
以及带有脚本模块和 shell 的脚本文件。
Ansible 给出了我更改的所有状态,但是当我尝试回显配置文件中的变量时,例如 echo $myname
他们在 playbook 中完成执行后什么也不打印。
当我尝试用终端再次加载它时 . /etc/profile
变量被加载并且我可以回显它的值。
我还在 profile.d 目录中创建了一个脚本文件并使用 Ansible 加载它,但没有任何反应。
ps. full root permissions is given with become and --ask-become-pass
parameter. I'm using vagrant box with centos 7 X64.
谢谢...
1) Sourcing the profile will only be good for a single task.
例如,如果您的个人个人资料(我还没有达到/etc/profile
)设置myname=Ameen
,那么在下面的代码中,第一个任务应该呼应你的名字,但第二个不应该:
- shell: 'cd; . ./.bash_profile; echo "[$myname]"`
- shell: 'echo "[$myname]"'
每项任务都是一个独特的环境。在本地 shell 环境中设置的变量将不可用于稍后连接但不会为自身再次设置的另一个环境。
我的输出:
[Ameen]
[]
2) bash uses .bash_profile
, which typically sources ~/.bashrc
, which usually sources /etc/bashrc
.
在 ksh
中通常是 ~/.profile
、~/.kshrc
和 /etc/profile
,尽管所有这些显然都是可配置的,只是约定俗成,可以完全不同地完成给定系统,尽管您应该考虑原因。
3) Are you really expecting myname
to be set in the global profile all users source?
或者这只是您问题的一个例子?
Ansible load my Variables into my global profile, it's ok not changed as it's already placed in that profile
I pass the script in same environment, so the java read the variables successfully
我尝试重新加载位于 /etc/profile 的 bash 配置文件时遇到问题。
我尝试通过多种方式加载它,从
命令:. /etc/profile
以及带有脚本模块和 shell 的脚本文件。
Ansible 给出了我更改的所有状态,但是当我尝试回显配置文件中的变量时,例如 echo $myname
他们在 playbook 中完成执行后什么也不打印。
当我尝试用终端再次加载它时 . /etc/profile
变量被加载并且我可以回显它的值。
我还在 profile.d 目录中创建了一个脚本文件并使用 Ansible 加载它,但没有任何反应。
ps. full root permissions is given with become and
--ask-become-pass
parameter. I'm using vagrant box with centos 7 X64.
谢谢...
1) Sourcing the profile will only be good for a single task.
例如,如果您的个人个人资料(我还没有达到/etc/profile
)设置myname=Ameen
,那么在下面的代码中,第一个任务应该呼应你的名字,但第二个不应该:
- shell: 'cd; . ./.bash_profile; echo "[$myname]"`
- shell: 'echo "[$myname]"'
每项任务都是一个独特的环境。在本地 shell 环境中设置的变量将不可用于稍后连接但不会为自身再次设置的另一个环境。
我的输出:
[Ameen]
[]
2) bash uses
.bash_profile
, which typically sources~/.bashrc
, which usually sources/etc/bashrc
.
在 ksh
中通常是 ~/.profile
、~/.kshrc
和 /etc/profile
,尽管所有这些显然都是可配置的,只是约定俗成,可以完全不同地完成给定系统,尽管您应该考虑原因。
3) Are you really expecting
myname
to be set in the global profile all users source?
或者这只是您问题的一个例子?
Ansible load my Variables into my global profile, it's ok not changed as it's already placed in that profile
I pass the script in same environment, so the java read the variables successfully