Advice: Declutter Your Dialplan Files

Hi,

This isn’t really a question or support request as much as it is me sharing a tip with the community. Maybe you know this; I did not see it documented and a few people I spoke to seemed surprised to hear this worked.

The extensions.conf file can get to be a pretty gnarly file. By default the documentation makes it seem like everything has to go there; so it’s not long before this file can become a very large complicated mess. Between all your internal extensions, IVRs, outbound rules, inbound rules, and everything else that relies on the dialplan; you could find yourself spending more time looking for what to edit.

The good news is…you don’t have to live this way! The same trick used for other service configurations on linux works with Asterisk; a “conf.d” folder! Simply put, it’s a folder in your configuration directory that contains multiple conf files; and your main configuration is setup to just read files out of this folder. Most processes typically name this folder “servicename.conf.d”.

Here is the contents of my /etc/asterisk/extensions.conf:

[globals]
#include extensions.d/*.conf

That’s it. Two lines. Wildcarded to make life easier. Asterisk now looks in /etc/asterisk/extensions.d/ and loads every .conf file contained within:

root@asteriskpbx:/etc/asterisk/extensions.d# ls
agent-dial.conf  americana.conf  cledus.conf     inbound-ivr.conf  jawdemo-juke.conf  tmnt.conf
al-hotline.conf  bhg.conf        grandma.conf    internal.conf     rucka-juke.conf    voipms.conf
al-juke.conf     callinspy.conf  huey-juke.conf  island-juke.conf  shackphone.conf

This has made my life so much easier. Having everything in it’s own file means I’m not scrolling through a large .conf file looking for the lines I need. I just drop things in a file, drop it in extensions.d/, and call it’s context name like normal.

Hope someone finds this helpful.

4 Likes

you should also do this for other config files, like pjsip.d and make file one for users and providers
another tip is to befor you edit an config file copy it to .org and then in the .conf remove all sample code so you have a clean config, this is especially relevant for pjsip.conf or sip.conf

as I have seen systems that have kept all the sample config from 1.4 all the way up to 18.X.X

1 Like

If you do that, and leave the folder empty, for future usage, Asterisk will complain.

Instead of just adding it when needed, you can prepare it with try include instead. Like so:

#tryinclude extensions.d/*.conf

That will make Asterisk not complain, if the files does not exist.

1 Like

Interesting… I knew about #include of course, but I never thought about including a directory, just individual files. Doesn’t surprise me, but never thought about it.

My dialplan is about 20,000 to 30,000 lines and as such almost from the beginning it was always in multiple files. I think I have about 70 to 80 #include’s, directly or indirectly, in extensions.conf, including some configs that are auto-generated by some scripts.

As far as I remember, it’s undocumented, but for my use where I have a script taking user configuration from a database, being able to include a directory pattern, or similar, works perfectly. My includes are something along the lines of

#tryinclude extensions.d/users.d/*/extensions_*.conf

In some cases you need to include files in a specific order, but that can usually be solved by making sure the important files have a unique pattern, then including the files based on patterns, in the right order.

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