我正在尝试将/usr/pgsql-10/bin添加到$PATH中,因为我希望使用该计算机的每个人都能够运行psql命令。
已尝试遵循this示例:
- name: add {{extra_path}} to path
lineinfile:
dest: /etc/environment
state: present
backrefs: yes
regexp: 'PATH=(["]*)((?!.*?{{extra_path}}).*?)(["]*)$'
line: "PATH=\1\2:{{extra_path}}\3"首先,我不太明白我到底应该如何修改它。我应该用我的路径(/usr/pgsql-10/bin)只替换extra_path还是整个{{extra_path}}。
我尝试了任何一种方法,都得到了不同的错误。更糟糕的是,我的/etc/environment甚至没有包含PATH。
发布于 2019-06-12 19:48:02
仅声明附加路径
vars:
extra_path: /usr/pgsql-10/bin基于Response to updating PATH with ansible - system wide的想法,下面的任务似乎是可行的
- name: 'Add {{ extra_path }} if PATH does not exist'
lineinfile:
path: /etc/environment
line: 'PATH="{{ extra_path }}"'
insertafter: EOF
when: lookup('file', '/etc/environment') is not search('^\s*PATH\s*=')
- name: 'Add {{ extra_path }} to PATH'
lineinfile:
path: /etc/environment
regexp: 'PATH=(["])((?!.*?{{ extra_path }}).*?)(["])$'
line: 'PATH=\1\2:{{ extra_path }}\3'
backrefs: yes
when: lookup('file', '/etc/environment') is search('^\s*PATH\s*=')(这是一个相当不错的reading。)
https://stackoverflow.com/questions/56560173
复制相似问题