Ansible 中的源 .bashrc

问题描述 投票:0回答:1

尝试在运行期间获取 .bashrc 中的更改,但是

- name: Set the environment variable for the current session
  shell: "export PATH=$PATH:$HOME/rc-binaries/"
  args:
    executable: /bin/bash

- name: Source the updated .bashrc
  shell: "source {{ ansible_env.HOME }}/.bashrc"
  args:
    executable: /bin/bash

- name: Enable auto-completion for commands
  shell: "rc --autocompletion"
  ignore_errors: true

但结果是: 没有这样的文件或目录:b'rc'

如何修复?

期望能够运行我们在下一个 Ansible 任务的路径中定义的二进制文件

shell automation ansible
1个回答
0
投票

每个任务都在单独的进程中运行。在一项任务中设置 shell 或环境变量绝对不会影响后续任务。您需要在单个任务中执行所有这些操作:

- shell: |
    export PATH=$PATH:$HOME/rc-binaries/
    source {{ ansible_env.HOME }}/.bashrc
    rc --autocompletion
  args:
    executable: /bin/bash
  ignore_errors: true
© www.soinside.com 2019 - 2024. All rights reserved.