无法使用ansible获取〜/.bashrc文件 [英] can not source ~/.bashrc file with ansible

查看:157
本文介绍了无法使用ansible获取〜/.bashrc文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文件.bash_aliases中有一个别名列表,该文件正使用ansible playbook复制到远程服务器.该文件已被复制到目标位置,但使用以下可完成的任务未加载.bashrc(反过来加载.bash_aliases)文件.

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"

不带参数

  - name: source the .bashrc file
    shell: source ~/.bashrc

带有原始模块

With raw module

  - name: source the .bashrc file
    raw: source ~/.bashrc

带命令模块 -名称:.bashrc文件的来源 命令:来源〜/.bashrc

With command module - name: source the .bashrc file command: source ~/.bashrc

没有任何效果!!!任何帮助

Nothing works!!! Any help

推荐答案

通过阅读您的评论,您表示您正在尝试使用永久别名,而不是针对特定会话.为什么不在需要使用这些特定别名而不是按用户使用的计算机上的/etc/profile.d内部创建那些别名?

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?

另外,由于我不是Ansible专家,在我对Ansible细节进行Google搜索时弹出的另一篇文章...

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)

史蒂夫·米格利

您可以通过两种方式使用带ansible的源.一种是使用"shell:"命令和/bin/sh(默认为ans). 源"称为".在/bin/sh中.因此,您的命令将是:

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]

请注意,您必须在采购.bashrc b/c之后运行命令,每个ssh会话是不同的-每个ansible命令都在单独的ssh事务中运行.

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.

您的第二个选择是强制Ansible shell使用bash,然后您可以使用"source"命令:\

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

最后,我要注意的是,如果您使用的是Ubuntu或类似版本,则可能希望实际获取"/etc/profile"的源代码,这样可以更完全地模拟本地登录."

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆