2017-02-12 33 views
1
- name: restarting .bash_profile 
    command: chdir=/home/ec2-user/ source .bash_profile 

我试图使用源命令.bash_profile文件中的.bash_profile文件,但它抛出一个错误:Ansible - 无法找到时,我用下面的代码

{"changed": false, "cmd": "source .bash_profile", "failed": true, "msg": "[Errno 2] No such file or directory", "rc": 2}

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

回答

2

source不是一个外部命令,你可以独立运行,所以你不能使用command模块(“没有这样的文件或目录”错误是指source,不.bash_profile)。

这是一个Bash内建的,所以你可以使用shell模块来执行它,但真正的问题是它不会对其他任务产生影响,我相信这是你的目标。

你可以做什么,是预先考虑其他命令,你可能想采购一个新的环境后运行,例如:

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