Ever since I met David Lutterkort over steaks at OLS 2007 augeas was this tool in the back of my mind that I couldn't place... I never saw the need for it... or it seemed to be huge overkill for the problem that needed solving .
Till I ran into sipxecs rewriting XML files on the fly .. and putting values in their XML that I could not trace back to an original source. As of Augeas 0.8.x there's an XML lens out there.
Digging innot blah.xml with augtool you can do stuff like
set /augeas/load/Xml/incl[3] /tmp/blah.xml
set /augeas/load/Xml/lens Xml.lns
load
print /files/tmp/blah.xml/profile/settings/param[17]/
/files/tmp/blah.xml/profile/settings/param[17] = "#empty"
/files/tmp/blah.xml/profile/settings/param[17]/#attribute
/files/tmp/blah.xml/profile/settings/param[17]/#attribute/name = "sip-ip"
/files/tmp/blah.xml/profile/settings/param[17]/#attribute/value = "10.255.202.90"
augtool> print /files/tmp/blah.xml/profile/settings/param[18]/
/files/tmp/blah.xml/profile/settings/param[18] = "#empty"
/files/tmp/blah.xml/profile/settings/param[18]/#attribute
/files/tmp/blah.xml/profile/settings/param[18]/#attribute/name = "ext-rtp-ip"
/files/tmp/blah.xml/profile/settings/param[18]/#attribute/value = "auto-nat"
augtool> print /files/tmp/blah.xml/profile/settings/param[16]/
/files/tmp/blah.xml/profile/settings/param[16] = "#empty"
/files/tmp/blah.xml/profile/settings/param[16]/#attribute
/files/tmp/blah.xml/profile/settings/param[16]/#attribute/name = "rtp-ip"
/files/tmp/blah.xml/profile/settings/param[16]/#attribute/value = "10.255.202.90"
and get and set
augtool> get /files/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml/profile/settings/param[17]/#attribute/value
/files/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml/profile/settings/param[17]/#attribute/value = 10.255.202.90
augtool> set /files/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml/profile/settings/param[16]/#attribute/value 10.0.0.2
Putting that into puppet however isn't that tvivial .
When you try to do this
augeas{"sipxprofile" :
changes => [
"set /augeas/load/Xml/incl[last()+1] /etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml",
"set /files/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml/profile/settings/param[16]/#attribute/value 10.0.0.2",
"set /files/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml/profile/settings/param[17]/#attribute/value 10.0.0.2",
],
}
Puppet really doesn't output what you want to do ... it only outputs the snippet you modify ..
It's the load statement above that is the really important piece but puppet can't directly work with that so you need to go around that using
The way to solve this is
augeas{"sipxprofile" :
lens => "Xml.lns",
incl => "/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml",
context => "/files/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml",
changes => [
"set profile/settings/param[16]/#attribute/value $ipaddress",
"set profile/settings/param[17]/#attribute/value $ipaddress",
],
onlyif => "get profile/settings/param[16]/#attribute/value != $ipaddress",
}