ConfD User Community

Can confd.conf inlcude/import another config file?

Just wonder whether confd.conf can include or import another config file ?
E.g.:
I have a ‘sub_confd.conf’, which has configs of “loadPath”. whether confd.conf can include or import this ‘sub_confd.conf’ to load the configs in it to confd.conf ?

Thanks.

I’m not aware of such functionality, I guess it is not supported.

Perhaps you can modify confd.conf before startup with some script and update/create loadPath. This can be done with e.g. xmlstarlet.

Here is shell example that modifies CLI ssh port (and creates it if does not exist), you can adapt it for loadPath. Path of confd.conf in example is /confd.conf.

if [ "$(xmlstarlet sel -N conf="http://tail-f.com/ns/confd_cfg/1.0" -t -v "count(/conf:confdConfig/conf:cli)" /confd.conf)" = "0" ]; then xmlstarlet ed -L -O -N conf="http://tail-f.com/ns/confd_cfg/1.0" -s /conf:confdConfig -t elem -n cli /confd.conf; fi
if [ "$(xmlstarlet sel -N conf="http://tail-f.com/ns/confd_cfg/1.0" -t -v "count(/conf:confdConfig/conf:cli/conf:ssh)" /confd.conf)" = "0" ]; then xmlstarlet ed -L -O -N conf="http://tail-f.com/ns/confd_cfg/1.0" -s /conf:confdConfig/conf:cli -t elem -n ssh /confd.conf; fi
if [ "$(xmlstarlet sel -N conf="http://tail-f.com/ns/confd_cfg/1.0" -t -v "count(/conf:confdConfig/conf:cli/conf:ssh/conf:port)" /confd.conf)" = "0" ]; then xmlstarlet ed -L -O -N conf="http://tail-f.com/ns/confd_cfg/1.0" -s /conf:confdConfig/conf:cli/conf:ssh -t elem -n port /confd.conf; fi
xmlstarlet ed -L -O -N conf="http://tail-f.com/ns/confd_cfg/1.0" -u "/conf:confdConfig/conf:cli/conf:ssh/conf:port" -v 10022 /confd.conf

Hm, this reminds me that there is a somewhat “similar” but probably much less sophisticated tool included in the ConfD release - xmlset. It is only shipped as source, in the $CONFD_DIR/src/confd/tools directory, and has its own Makefile there:

$ cd $CONFD_DIR/src/confd/tools
$ make -f Makefile.xmlset 
cc -std=c99 -Wall -pedantic   -c -o xmlset.o xmlset.c
(omit warnings that could easily be fixed)
cc -std=c99 -Wall -pedantic  -o xmlset xmlset.o -lexpat
strip xmlset
$ ./xmlset --help
Usage: ./xmlset R Tag ... < XmlFile
Usage: ./xmlset C NewValue Tag ... < XmlFile

(where R is for Remove and C is for Change). Might be useful for trivial changes. You can of course also use a generic text processor such as m4 to combine bits and pieces into the final confd.conf.