The following line of code is throwing an environment variable was not found
error in a RHEL8 virtual machine running in Azure:
sourceKeys = os.environ.get("MY_ENV_VAR")
However, when we putty into the VM, we are able to access the variable as follows:
$ echo $MY_ENV_VAR
/path/to/some.yaml
The variable is set by packer in a startup script that has the following code:
export MY_ENV_VAR='/path/to/some.yaml'
echo "export MY_ENV_VAR='/path/to/some.yaml'" >> /etc/environment
echo "export MY_ENV_VAR='/path/to/some.yaml'" >> /etc/bashrc
echo "export MY_ENV_VAR='/path/to/some.yaml'" >> /etc/profile
Why is the linux terminal able to read the environment variable while python is not?
What needs to change in order for the python program to be able to read the environment variable's value?