[asterisk-users] Conditional "includes" in iax.conf

Steve Edwards asterisk.org at sedwards.com
Wed Jul 7 15:28:03 CDT 2010


On Wed, 7 Jul 2010, Scott Stingel wrote:

> For maintenance purposes, if possible I'd like to use the same iax.conf 
> file in several different asterisk systems.  However, on one of the 
> systems only, I would like to include an IAX "register" command to 
> another external system.
>
> Within iax.conf or other configuration files (other than 
> extensions.conf), is there a way of determining what system I'm running 
> on, and include a particular configuration item conditionally?  I guess 
> what I'm asking is there a way to conditionally "include" lines in a 
> configuration depending on the value of some linux environment variable?

I ran into this a couple of years ago.

I looked at several "preprocessors" like gcc, sed, m4 and others I've 
since forgotten. I settled on:

http://mxr.mozilla.org/mozilla-central/source/config/preprocessor.pl

It's been "deprecated" in favor of a Python script, but it still works 
fine.

It allows you to do "includes" and token substitutions.

I cobble it all up in my makefile so I just type "make config" to make all 
of the configuration files needed on each host.

A "source" config file looks like this iax.conf.pre snippet:

#if     HOSTNAME!=example
; calls from example
[general](+)
         register                        = @HOSTNAME@:@PASSWORD@@example.vtpv.privatebilling.com
#endif
[example]
         context                         = start
         host                            = dynamic
         qualify                         = yes
         secret                          = example
         trunk                           = yes
         type                            = friend
         username                        = example

; (end of /etc/asterisk/@PROJECT@/iax.conf)

And then the makefile entry looks like:

config:
# /etc/asterisk/
         for     FILE in\
                         asterisk.conf\
                         extensions.ael\
                         extensions.conf\
                         iax.conf\
                         iaxprov.conf\
                         logger.conf\
                         manager.conf\
                         meetme.conf\
                         modules.conf\
                         musiconhold.conf\
                         rtp.conf\
                         sip.conf\
                         ;\
                 do\
                 preprocessor.pl -E -I preprocessor.pre $$FILE.pre\
                         >/etc/asterisk/${PROJECT}/$$FILE;\
                 chmod u=rw,g=r,o=r /etc/asterisk/${PROJECT}/$$FILE;\
                 done
         sudo /etc/init.d/asterisk reload

This has been a big time saver for me. I only have to maintain a single 
set of configuration files and any changes can be automagically rolled out 
and applied to all of the hosts using "make rsync; make remote-config."

In addition to the files in /etc/asteris/, I use this method to maintain:

 	/etc/hosts
 	/etc/init.d/asterisk
 	/etc/sysconfig/iptables
 	/scripts/* (project specific scripts)
 	/usr/local/etc/openser/dispatcher.list
 	/var/spool/cron/*
 	~/.my.cnf

across multiple projects and many hosts.

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000



More information about the asterisk-users mailing list