On 12/18/2012 09:46 AM, Dominic Cleal wrote:
On 17/12/12 15:00, Jens Hoffmann wrote:
I need to add interfaces (eth0, eth1, ...) one at a time to INTERFACES in
/etc/default/isc-dhcp-server like so:

set /files/etc/default/isc-dhcp-server/INTERFACES/value[last()+1] eth0
set /files/etc/default/isc-dhcp-server/INTERFACES/value[last()+1] eth1
....
Are you using augtool for your application, or one of the APIs, or Puppet?

But /etc/default/isc-dhcp-server is parsed by shellvars.aug that only
allows to issue commands like:


set /files/etc/default/isc-dhcp-server/INTERFACES "\"eth0 eth1 ...\""



I tried to overcome this limitation with my own module that uses the lense 
defined
in shellvars_list.aug and solely includes "/etc/default/isc-dhcp-server". But 
then
neither the shellvars module nor my own one applies to the dhcp configuration 
file:
the configuration file is left ignored without any error messages.
Did you check for errors with "print /augeas//error"?  augtool will only
print and halt on fatal errors.

I would expect your solution to fail, as Augeas should see that two
modules are attempting to load the same file (there's no concept of
precedence).  Instead, you should disable autoloading and explicitly
load the file with the lens you want:

$ augtool --noautoload
augtool> set /augeas/load/Shellvars_list/lens Shellvars_list.lns
augtool> set /augeas/load/Shellvars_list/incl /etc/default/isc-dhcp-server
augtool> load

The APIs also support this mode using the AUG_NO_MODL_AUTOLOAD flag.


Thank you for that hint. This basically solves my problem. I did not realize that lenses
can be loaded / unloaded dynamically.


I use augeas with puppet and (for anybody interested) mysolution there now looks like:


    augeas { "let dhcp listen to ${my_interface}":
        lens => "Shellvars_list.lns",
        incl => "/etc/default/isc-dhcp-server",
        context => "/files/etc/default/isc-dhcp-server",
        changes => [
            "set INTERFACES/value[last()+1] ${my_interface}"
        ],
onlyif => ["match INTERFACES/value[. = \"$my_interface\"] size == 0"],
        notify => Service["isc-dhcp-server"]
    }



I think this report can be marked as 'invalid' or so.


Thanks again,
Jens Hoffmann


--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to