无法使用 ansible 获取 ~/.bashrc 文件 [英] can not source ~/.bashrc file with ansible
问题描述
我在文件 .bash_aliases
中有一个别名列表,该文件正在使用 ansible playbook
复制到远程服务器.该文件正在被复制到目的地,但 .bashrc
(它依次加载 .bash_aliases
)文件没有使用以下 ansible 任务加载.
我尝试给出可执行参数
- 名称:源 .bashrc 文件外壳:源 ~/.bashrc参数:可执行文件:/bin/bash"
<块引用>
无需论证
- 名称:源 .bashrc 文件外壳:源 ~/.bashrc
<块引用>
使用原始模块
- 名称:源 .bashrc 文件原始:源 ~/.bashrc
带命令模块- 名称:来源 .bashrc 文件命令:source ~/.bashrc
没有任何效果!!!任何帮助
通过阅读您的评论,您表示您正在尝试创建永久别名,而不是针对特定会话.为什么不在您需要使用这些特定别名的机器上的/etc/profile.d 中创建这些别名,而不是由用户创建?
另外,当我在谷歌搜索 Ansible 细节时弹出的另一篇文章,因为我不是 Ansible 专家...... 无法使用 Ansible 获取 .bashrc(感谢 @chucksmash 提供链接)
史蒂夫·米奇利
您有两个选项可以将源与 ansible 结合使用.一种是使用shell:"命令和/bin/sh(ansible 默认值).源"被称为."在/bin/sh 中.所以你的命令是:
-name: 源 bashrc须藤:没有贝壳: ./home/username/.bashrc &&[您要运行的实际命令]
请注意,您必须在获取 .bashrc b/c 之后运行命令,每个 ssh 会话都是不同的 - 每个 ansible 命令都在单独的 ssh 事务中运行.
您的第二个选择是强制 Ansible shell 使用 bash,然后您可以使用source"命令:\
名称:源 bashrc须藤:没有shell: source/home/username/.bashrc &&[您要运行的实际命令]参数:可执行文件:/bin/bash
最后,我会注意到,如果您使用的是 Ubuntu 或类似设备,则您可能希望实际获取/etc/profile",这更完全地模拟了本地登录."
I have a list of aliases in a file, .bash_aliases
, which is being copied to remote servers with ansible playbook
. The file is getting copied to the destination but the .bashrc
(which in turns load the .bash_aliases
) file is not getting loaded using the following ansible task.
I have tried giving the executable argument
- name: source the .bashrc file
shell: source ~/.bashrc
args:
executables: "/bin/bash"
Without argument
- name: source the .bashrc file
shell: source ~/.bashrc
With raw module
- name: source the .bashrc file
raw: source ~/.bashrc
With command module - name: source the .bashrc file command: source ~/.bashrc
Nothing works!!! Any help
From reading your comments, you stated that you are trying to make permanate aliases and not for a particular session. Why not create those aliases inside of /etc/profile.d on the machines you need to have those particular aliases on instead of by user?
Also, from another post that popped up when I ran a google search on Ansible specifics as I am no Ansible expert... Not possible to source .bashrc with Ansible (thanks to @chucksmash for the link)
"Steve Midgley
You have two options to use source with ansible. One is with the "shell:" command and /bin/sh (the ansible default). "source" is called "." in /bin/sh. So your command would be:
-name: source bashrc
sudo: no
shell: . /home/username/.bashrc && [the actual command you want run]
Note you have to run a command after sourcing .bashrc b/c each ssh session is distinct - every ansible command runs in a separate ssh transaction.
Your second option is to force Ansible shell to use bash and then you can use the "source" command:\
name: source bashrc
sudo: no
shell: source /home/username/.bashrc && [the actual command you want run]
args:
executable: /bin/bash
Finally, I'll note that you may want to actually source "/etc/profile" if you're on Ubuntu or similar, which more completely simulates a local login."
这篇关于无法使用 ansible 获取 ~/.bashrc 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!