Everything is a Freaking DNS problem - sipxecs http://127.0.0.1:8080/blog/taxonomy/term/1459/0 en The case for Augeas http://127.0.0.1:8080/blog/case-augeas <p>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 .</p> <p>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.</p> <p>Digging innot blah.xml with augtool you can do stuff like</p> <p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;"><ol><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">set /augeas/load/Xml/incl[3] /tmp/blah.xml</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">set /augeas/load/Xml/lens Xml.lns</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">load</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">print /files/tmp/blah.xml/profile/settings/param[17]/</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/tmp/blah.xml/profile/settings/param[17] = &quot;#empty&quot;</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/tmp/blah.xml/profile/settings/param[17]/#attribute</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/tmp/blah.xml/profile/settings/param[17]/#attribute/name = &quot;sip-ip&quot;</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/tmp/blah.xml/profile/settings/param[17]/#attribute/value = &quot;10.255.202.90&quot;</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">augtool&gt; print /files/tmp/blah.xml/profile/settings/param[18]/</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/tmp/blah.xml/profile/settings/param[18] = &quot;#empty&quot;</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/tmp/blah.xml/profile/settings/param[18]/#attribute</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/tmp/blah.xml/profile/settings/param[18]/#attribute/name = &quot;ext-rtp-ip&quot;</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/tmp/blah.xml/profile/settings/param[18]/#attribute/value = &quot;auto-nat&quot;</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">augtool&gt; print /files/tmp/blah.xml/profile/settings/param[16]/</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/tmp/blah.xml/profile/settings/param[16] = &quot;#empty&quot;</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/tmp/blah.xml/profile/settings/param[16]/#attribute</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/tmp/blah.xml/profile/settings/param[16]/#attribute/name = &quot;rtp-ip&quot;</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/tmp/blah.xml/profile/settings/param[16]/#attribute/value = &quot;10.255.202.90&quot;</div></li></ol></pre></div></p> <p>and get and set</p> <p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;"><ol><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">augtool&gt; get /files/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml/profile/settings/param[17]/#attribute/value</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">/files/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml/profile/settings/param[17]/#attribute/value = 10.255.202.90</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">augtool&gt; set /files/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml/profile/settings/param[16]/#attribute/value 10.0.0.2</div></li></ol></pre></div></p> <p>Putting that into puppet however isn't that tvivial .</p> <p>When you try to do this</p> <p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;"><ol><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">augeas{&quot;sipxprofile&quot; :</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> changes =&gt; [</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> &quot;set /augeas/load/Xml/incl[last()+1] /etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml&quot;,</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> &quot;set /files/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml/profile/settings/param[16]/#attribute/value 10.0.0.2&quot;,</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> &quot;set /files/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml/profile/settings/param[17]/#attribute/value 10.0.0.2&quot;,</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> ],</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> }</div></li></ol></pre></div></p> <p>Puppet really doesn't output what you want to do ... it only outputs the snippet you modify ..<br /> 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<br /> The way to solve this is</p> <p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;"><ol><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">augeas{&quot;sipxprofile&quot; :</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> lens =&gt; &quot;Xml.lns&quot;,</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> incl =&gt; &quot;/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml&quot;,</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> context =&gt; &quot;/files/etc/sipxpbx/freeswitch/conf/sip_profiles/sipX_profile.xml&quot;,</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> changes =&gt; [</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> &quot;set profile/settings/param[16]/#attribute/value $ipaddress&quot;,</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> &quot;set profile/settings/param[17]/#attribute/value $ipaddress&quot;,</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> ],</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal"> onlyif =&gt; &quot;get profile/settings/param[16]/#attribute/value != $ipaddress&quot;,</div></li><li style="font-family: monospace; font-weight: normal;"><div style="font-family: monospace; font-weight: normal; font-style: normal">}</div></li></ol></pre></div></p> http://127.0.0.1:8080/blog/case-augeas#comments augeas devops lens puppet sipxecs xml Fri, 10 Jun 2011 14:26:18 +0000 Kris Buytaert 1044 at http://127.0.0.1:8080/blog