Configafe Config Environment Variables

Trying to use ${HOSTNAME} in the configuration file does not work! According to the documentation, configuration files should allow environment variables, as indicated in the documents:

Lookups

return to environment variables if they are not resolved in the configuration itself, so $ {HOME} will work as you expect. In addition, most configurations combine system properties, so you can use $ {user.home}.

Is there a way to get the hostname in the configuration file?

Play
Add host.name=${HOSTNAME} to the application.conf file, then try to access it from anywhere. For example, try adding

 Logger.info(s"Hostname is ${current.configuration.getString("host.name").getOrElse("NOT-FOUND")}") 

at Global.scala .

Environment
This was done in the RHEL6 environment, where echo $HOSTNAME creates precise32 , so there is an environment variable, it is not a hostname program.

+8
akka playframework configuration typesafe
source share
3 answers

The solution seems to pass the host name through the system property as -Dhost.name=$HOSTNAME or -Dhost.name=$(hostname) . I would suggest that in windows this will be something else, but this works for NIX environments.

If anyone can come up with something cleaner, this will be an accepted answer.

+7
source share

This probably doesn't work because $HOSTNAME apparently not an environment variable:

 jamesw@T430s:~$ echo $HOSTNAME T430s jamesw@T430s:~$ export|grep HOSTNAME jamesw@T430s:~$ 

So it must be some other special bash thing.

+6
source share

You should see if the call to System.getenv("HOSTNAME") returns a nonzero value. If not, HOSTNAME not an env variable according to the java environment, which is important for matching with the configuration property in config-config. I tried this with a HOSTNAME , and although I could repeat it in bash, it was not available in java as a replacement for env. I changed it to USER and everything worked as expected.

+1
source share

All Articles