When I try to get the values using ConfigParser,
I am not able to get certain values from environment variables in my .ini file
Interpolating variable names are printing variables as it is without value substitution.
Below is my code,
config_parse.py:
import os
import configparser
myConf = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
myConf.read('config_data.ini')
print( myConf.get('server_details', 'hostName', vars=os.environ))
print( myConf.get('server_details', 'userName', vars=os.environ))
print( myConf.get('log_path', 'mntPath', vars=os.environ))
exit(0)
config_data.ini:
[server_details]
hostName: %(HOSTNAME)
; Below value are not getting substituted from environment variable
userName: %(USER)
password: passw0rd
[log_path]
instance: %(SERVER_INSTANCE)
mntPath: /net/server1/mnt/data0
; server_details:hostname and instance values are not getting substituted
testbedMntPath: ${mntPath}/${server_details:userName}/my_logs/${server_details:hostName}${instance}
I am getting the following output,
$] python config_parse.py
server1
%(USER)
/net/server1/mnt/data0/%(USER)/my_logs/%(HOSTNAME)%(SERVER_INSTANCE)
$]