How to append to the PATH

I need to update the PATH variable on the target machine. Yet I have no idea how to do it.

I could update /etc/environment with an ansible play, but does that do what I want without overwriting the user’s PATH instead of appending to it?

What’s the best way of doing this?

It depends on your shell, interactive or non interactive shell, your distribution and for which user you would like to change the path for.

Interactive Bash support files in /etc/profile.d/ and this will be added to all users.

To add to the path just create a file like this.

- name: My custom path
   copy:
     dest: /etc/profile.d/my_custom_path.sh
     content: "PATH=PATH:/my/custom/path"