Environmental variables

Hello, noob here.

Is it possible to access environmental variables within conf files?

This is related to a much broader question on how to handle conf files within a git repo and inject sensitive secrets into the config files, such as runtime environmental variables.

I have tried the ${ENV(AST_PASSWORD)} but no success. Is it config specific? I.e. some conf files will allow ${ENV()} where others won’t?

The config files I am looking to use envvars are:

sip.conf
pjsip.conf
ari.conf

Generally variable substitution is only done on dialplans, although there might be the odd exception that I’m not aware of. That means extensions.conf and extensions.ael,etc. They are done at run time, not at configuration load time

Thank you, appreciate the quick response. I suspected this would be the case.

What is the best practice for handling secrets in config files between repo and production? EnvVars would have been the easiest route but that doesn’t appear to be an option, there are alternatives, e.g. using sed to read/replace EnvVars and injecting it into the config at build stage - workable but a bit of a pain.

Would the #exec directive help?

1 Like

You could generate the config filed thru some script using

#exec /var/opt/your_script.py

You can create an included file like that:

#include vars_custom.conf

with this content:

globals
SysToken = wof9Quoi
JiraToken = eel7ahkimaeGhi2i

Then use ${SysToken} in your dialplan configs.
And set to never upload vars_custom.conf to your repo.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.