What specific syntax must be changed below in order for Ansible to successfully add
/home/another-user/bin
to the $PATH variable on a RHEL 7 VM?
Current Version of Playbook:
The playbook we are using sets a variable for the /home/another-user/bin
and then uses the variable to add a line to /etc/environment
as follows:
vars:
extra_path: /home/another-user/bin
vars_files:
- myVars.yaml
#Other stuff
- name: Update /etc/environment for newly loaded apps
lineinfile:
dest: /etc/environment
line: "export PATH={{ extra_path }}:$PATH"
owner: root
become: true
become_user: root
vars:
ansible_become_password: "{{ root_pass_word }}"
BAD RESULT
The problem is that the above example is destroying all existing entries in the $PATH so that basic commands like cat
and others are no longer recognized:
[my-user@ip-10-0-0-171 ~]$ echo $PATH
/home/another-user/bin:$PATH:/usr/local/sbin:/usr/sbin:/home/my-user/.local/bin:/home/my-user/bin
[my-user@ip-10-0-0-171 ~]$ cat /etc/environment
-bash: cat: command not found
[my-user@ip-10-0-0-171 ~]$
I did find other examples using regular expressions here and on Stack Overflow, but those examples causes the same problem of command not found
by munging the /etc/environment
in one way or another.
$PATH
is not defined in the first place. No idea why. As a workaround add:/bin:/usr/bin
to it -cat
is placed in some of these paths.