include, tryinclude and exec
There are two other constructs we can use within all of our configuration files. They are #include and #exec.
The #include construct tells Asterisk to read in the contents of another configuration file, and act as though the contents were at this location in this configuration file. The syntax is #include filename, where filename is the name of the file you'd like to include. This construct is most often used to break a large configuration file into smaller pieces, so that it's more manageable. The asterisk/star character will be parsed in the path, allowing for the inclusion of an entire directory of files. If the target file specified does not exist, then Asterisk will not load the module that contains configuration with the #include directive.
The #tryinclude construct is the same as #include except it won't stop Asterisk from loading the module when the target file does not exist.
The #exec takes this one step further. It allows you to execute an external program, and place the output of that program into the current configuration file. The syntax is #exec program, where program is the name of the program you'd like to execute.
The #exec, #include, and #tryinclude constructs do not work in the following configuration files:
Let's look at example of both constructs in action. This is a generic example meant to illustrate the syntax usage inside a configuration file.
You can use #tryinclude if there is any chance the target file may not exist and you still want Asterisk to load the configuration for the module.
Here is a more realistic example of how #exec might be used with real-world commands.