Ansible - 当我使用以下代码时无法找到.bash_profile文件

时间:2017-02-12 00:06:37

标签: linux ansible .bash-profile

- name: restarting .bash_profile
  command: chdir=/home/ec2-user/ source .bash_profile

我尝试对.bash_profile文件使用source命令,但它引发了错误:

  

{"更改":false," cmd":"来源.bash_profile","失败":是," msg":" [Errno 2]没有这样的文件或目录"," rc":2}

但该文件存在于给定路径中。有没有办法可以为.bash_profile文件运行该命令?

1 个答案:

答案 0 :(得分:3)

source不是您可以独立运行的外部命令,因此您无法使用command模块(“没有此类文件或目录”错误指的是source,而非.bash_profile)。

它是一个内置的Bash,所以你可以使用shell模块来执行它,但真正的问题是它对其他任务没有影响,我认为这是你的目标。

您可以做的是添加另一个命令,您可能希望在获取新环境后运行该命令,例如:

- shell: source .bash_profile && my_command
  args:
    chdir: /home/ec2-user/
    executable: /bin/bash