I got this 'magic' out of the config file parser from Puppet.
I tried to use the config parser but couldn't get it to work so decided to simplify it.