【问题标题】:Ansible - not able to find .bash_profile file when I'm using the following codeAnsible - 当我使用以下代码时无法找到 .bash_profile 文件
【发布时间】:2017-02-13 11:29:59
【问题描述】:
- name: restarting .bash_profile
  command: chdir=/home/ec2-user/ source .bash_profile

我正在尝试对 .bash_profile 文件使用 source 命令,但它抛出了一个错误:

{"changed": false, "cmd": "source .bash_profile", "failed": true, "msg": "[Errno 2] 没有这样的文件或目录", "rc": 2}

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

【问题讨论】:

    标签: linux ansible .bash-profile


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2017-02-23
      • 2022-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-06
      • 2013-12-24
      • 1970-01-01
      相关资源
      最近更新 更多