<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.E-MailFormatvorlage17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hi Raphaël,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>thank you again for your kind and response!<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>This neat trick using defvar works just fine with augtool, which I only used for demonstrating my use case. Actually I need to solve this problem through Puppet.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Puppet does support checking the necessity for changes with Augeas before they are carried out (by means of the 'onlyif' parameter to the augeas defined type). Though I try my best to avoid that, since these checks can only be applied once for a set of changes. Splitting my changes in smaller sets introduces issues with the order they are applied in to the file. Chances are, that the same trick working for augtool can be used in Puppet, too, though I haven't tested it, yet.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Ciao,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Xavier.<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=DE style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=DE style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Raphaël Pinson [mailto:raphael.pinson@camptocamp.com] <br><b>Sent:</b> Friday, February 12, 2016 6:45 PM<br><b>To:</b> Mol, Xavier (SCC)<br><b>Cc:</b> augeas-devel@redhat.com<br><b>Subject:</b> Re: [augeas-devel] How to select nodes in distinct position, possibly creating them?<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>Hi Xavier,<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>There is not easy way using augtool. When using the Augeas API (in any language), you can easily check for the presence of a node and decide if you need to create it or not. In augtool, you can't do that (yet, until the Lua code is merged). There is a little trick you can use though, using defvar:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal># define $nomatch as /t if it doesn't have an "A" node<o:p></o:p></p></div><div><p class=MsoNormal>augtool> defvar nomatch /t[count(A)=0]<o:p></o:p></p></div><div><p class=MsoNormal># insert using $nomatch, which may not be defined<o:p></o:p></p></div><div><p class=MsoNormal>augtool> ins A before $nomatch/B<o:p></o:p></p></div><div><p class=MsoNormal># You are sure it exists now<o:p></o:p></p></div><div><p class=MsoNormal>augtool> set /t/A "value"<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Raphaël<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div></div><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On Fri, Feb 12, 2016 at 4:13 PM, Mol, Xavier (SCC) <<a href="mailto:xavier.mol@kit.edu" target="_blank">xavier.mol@kit.edu</a>> wrote:<o:p></o:p></p><p class=MsoNormal>Hello Augeas experts,<br><br>I'm looking for a way to select a node in an Augeas tree in a distinct position, which isn't difficult, but I also want to create that node in case it doesn't exist yet, which seems impossible to me as of now. An example probably illustrates better what I mean...<br><br>augtool> touch /t/#comment<br>augtool> ins "" after /t/*[last()]<br>augtool> touch /t/B<br>augtool> touch /t/C<br>augtool> print /t<br>/t<br>/t/#comment<br>/t/<br>/t/B<br>/t/C<br><br><br>What can I do now to make a node "A" appear right in front of "B"? The straight forward answer is, like this:<br><br>insert "A" before "B"<br><br>That works fine as long as there is no "A" node already, which I can't know beforehand. I could guarantee that there is no such node, by deleting it first (this very trick was taken from the Augeas wiki: <a href="https://github.com/hercules-team/augeas/wiki/Path-expressions#Tips_amp_Tricks" target="_blank">https://github.com/hercules-team/augeas/wiki/Path-expressions#Tips_amp_Tricks</a>).<br><br>augtool> rm /t/A[following-sibling::*[1][self::B]]<br>rm : /t/A[following-sibling::*[1][self::B]] 0<br><br><br>However, this way I might destroy any children of "A", which henceforth are lost. In other words, I'd replace "A" instead of updating it.<br><br><br>Normally one selects specific nodes with 'defnode', which will create new nodes if no match was found.<br><br>augtool> defnode newNode /t/A[following-sibling::*[1][self::B]]<br>augtool> print /t<br>/t<br>/t/#comment<br>/t/<br>/t/B<br>/t/C<br>/t/A<br><br>The problem this time is, that the new node will be appended to tree in last position, so it needs to be moved to the correct position manually. And 'mv' in turn has the inherent drawback, that it cannot target relative positions, only specific destinations. Which means, replacing existing nodes, which I don't want.<br><br>Does someone maybe have a solution to this? Or is this another situation that needs to be dealt with by applications utilizting Augeas, since Augeas doesn't interpret the format of the files it edits?<br><br>Thank you for your time,<br>Xavier.<br><br>PS: I'll be on holidays next week, so I won't be able to answer any replies until I've returned.<br><br><br>****<br>Karlsruher Institute of Technology (KIT)<br>Steinbuch Centre for Computing (SCC)<br><br>B. Sc. Xavier Mol<br>GridKa Storage Administrator and Support Manager<br><br>Hermann-von-Helmholtz-Platz 1<br>Geb. 449<br>76344 Eggenstein-Leopoldshafen<br>Phone: <a href="tel:%2B49%20721%20608%2023041">+49 721 608 23041</a><br>Email: <a href="mailto:xavier.mol@kit.edu">xavier.mol@kit.edu</a><br><a href="http://www.kit.edu" target="_blank">www.kit.edu</a><br>KIT - University of the State of Baden-Württemberg and National Large-scale Research Center of the Helmholtz Association<br>"Since 2010, the KIT has been certified as a family-friendly university."<br>****<br><br><br><br>_______________________________________________<br>augeas-devel mailing list<br><a href="mailto:augeas-devel@redhat.com">augeas-devel@redhat.com</a><br><a href="https://www.redhat.com/mailman/listinfo/augeas-devel" target="_blank">https://www.redhat.com/mailman/listinfo/augeas-devel</a><o:p></o:p></p></div><p class=MsoNormal><br><br clear=all><o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><p class=MsoNormal>-- <o:p></o:p></p><div><div><div><div><p class=MsoNormal>Raphaël Pinson<o:p></o:p></p><div><p class=MsoNormal>Infrastructure Developer & Training Leader<o:p></o:p></p></div><div><p class=MsoNormal>+33 458 482 013<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Camptocamp France<br>Savoie Technolac<br>BP 352<br>48, avenue du Lac du Bourget<br>73372 Le Bourget du Lac, Cedex<br><a href="http://www.camptocamp.com" target="_blank">www.camptocamp.com</a><o:p></o:p></p></div></div></div></div></div></div></div></div></div></body></html>