有没有办法:
export PATH=$PATH:/new/path/to/bin
在 Ansible 中,如果可能的话,不使用 shell 或命令。
我试过这个
- name: Add another bin dir to system-wide $PATH.
copy:
dest: /etc/profile.d/custom-path.sh
content: 'PATH=$PATH:{{ my_custom_path_var }}'
我从: https://www.jeffgeerling.com/comment/reply/2799
但它不起作用,因为 PATH 会导致:
$PATH:/new/path/to/bin
破坏系统的路径。
使用 shell 或命令是:
- name: Add pm2 to PATH
shell: echo "PATH=$PATH:/new/path/to/bin" > /etc/environment
become: true
但我仍然更喜欢不使用 shell/命令的选项。
不使用外壳模块的解决方案 而不是
content: 'PATH=$PATH:{{ my_custom_path_var }}'
用
content: 'export PATH=$PATH:{{ my_custom_path_var }}'