Hi Raphaël,
thank you again for your kind and response! 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. 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. Ciao, Xavier. From: Raphaël Pinson [mailto:raphael.pin...@camptocamp.com] Sent: Friday, February 12, 2016 6:45 PM To: Mol, Xavier (SCC) Cc: augeas-devel@redhat.com Subject: Re: [augeas-devel] How to select nodes in distinct position, possibly creating them? Hi Xavier, 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: # define $nomatch as /t if it doesn't have an "A" node augtool> defvar nomatch /t[count(A)=0] # insert using $nomatch, which may not be defined augtool> ins A before $nomatch/B # You are sure it exists now augtool> set /t/A "value" Raphaël On Fri, Feb 12, 2016 at 4:13 PM, Mol, Xavier (SCC) <xavier....@kit.edu> wrote: Hello Augeas experts, 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... augtool> touch /t/#comment augtool> ins "" after /t/*[last()] augtool> touch /t/B augtool> touch /t/C augtool> print /t /t /t/#comment /t/ /t/B /t/C What can I do now to make a node "A" appear right in front of "B"? The straight forward answer is, like this: insert "A" before "B" 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: https://github.com/hercules-team/augeas/wiki/Path-expressions#Tips_amp_Tricks). augtool> rm /t/A[following-sibling::*[1][self::B]] rm : /t/A[following-sibling::*[1][self::B]] 0 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. Normally one selects specific nodes with 'defnode', which will create new nodes if no match was found. augtool> defnode newNode /t/A[following-sibling::*[1][self::B]] augtool> print /t /t /t/#comment /t/ /t/B /t/C /t/A 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. 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? Thank you for your time, Xavier. PS: I'll be on holidays next week, so I won't be able to answer any replies until I've returned. **** Karlsruher Institute of Technology (KIT) Steinbuch Centre for Computing (SCC) B. Sc. Xavier Mol GridKa Storage Administrator and Support Manager Hermann-von-Helmholtz-Platz 1 Geb. 449 76344 Eggenstein-Leopoldshafen Phone: +49 721 608 23041 <tel:%2B49%20721%20608%2023041> Email: xavier....@kit.edu www.kit.edu KIT - University of the State of Baden-Württemberg and National Large-scale Research Center of the Helmholtz Association "Since 2010, the KIT has been certified as a family-friendly university." **** _______________________________________________ augeas-devel mailing list augeas-devel@redhat.com https://www.redhat.com/mailman/listinfo/augeas-devel -- Raphaël Pinson Infrastructure Developer & Training Leader +33 458 482 013 Camptocamp France Savoie Technolac BP 352 48, avenue du Lac du Bourget 73372 Le Bourget du Lac, Cedex www.camptocamp.com
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ augeas-devel mailing list augeas-devel@redhat.com https://www.redhat.com/mailman/listinfo/augeas-devel