interactive, not login shell support
Task
- name: Maven path configuration
will not work for not login shells (e.g. when role is used with docker containers), where /etc/profile is not used. Modifying ~/.bashrc solves the issue:
- name: Maven path configuration
blockinfile:
path: /root/.bashrc
block: |
M2_HOME={{maven_home_parent_directory}}/apache-maven-{{maven_version}}
PATH=$PATH:$M2_HOME/bin
state: present
Sorry, my apologies for the late reply and thanks for the interest.
Lack of proper (& automated) testing, on my side, requires more time to test. To be honest main issue is about taking a proper decision. From the snippet provided I am not sure I have a full understanding. You suggest to replace current path configuration or to add this new block. Would non-docker installation still work after that? Is there any official documentation that supports usage of /root/.bashrc for setting PATH / env variables? Ubuntu official documentation (albeit non-docker) EnvironmentVariables
That snippet is just a proposal of an additional task. From referenced ubuntu official documentation:
Shell config files such as ~/.bashrc, ~/.bash_profile, and ~/.bash_login are often suggested for setting environment variables. While this may work on Bash shells for programs started from the shell, variables set in those files are not available by default to programs started from the graphical environment in a desktop session.
When you run bash in docker container (e.g. docker run image_name bash), the default shell is not a login shell, which means profile files (or those in /etc/profile.d) are not sourced. ext ref.
Hi, There is a difference between /root/.bashrc and ~/.bashrc. And the assumption that docker container will run as root might not work. As per docker documentation If a service can run without privileges, use USER to change to a non-root user Maybe one option will be to parameterize the user, however, this needs some time/thinking.
thanks again