<div dir="ltr">Hi Andrew,<br><br><div class="gmail_extra"><div class="gmail_quote">On Sun, Jan 25, 2015 at 12:47 AM, Andrew Beverley <span dir="ltr"><<a href="mailto:andy@andybev.com" target="_blank">andy@andybev.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi guys,<br>
<br>
Firstly, thanks for Augeas. I've only just come across it, but it's<br>
really useful!<br>
<br>
I'm using Augeus to alter an sshd config file. For simple options, I can<br>
just do (for example):<br>
<br>
    set /files/etc/ssh/sshd_config/PermitRootLogin without-password<br>
<br>
If it's not set, then it will be added, if it is set, then it will be<br>
updated as required.<br>
<br>
However, what if I want to ensure that a particular group is in<br>
AllowGroups? I can do<br>
<br>
    set /files/etc/ssh/sshd_config/AllowGroups/0 sshers<br>
<br>
But that will only work if that's the only group I set.<br>
<br>
Is there a way I can say "add this value if it doesn't already exist"?<br></blockquote><div><br></div><div>There's no way currently to do that in Augeas; to get this sort of conditional logic, you'd have to resort to some sort of scripting language (e.g., using hte Python or Ruby bindings)<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

I realise that I can check the value first (which is what I am doing<br>
now) but it would be nice to be able to write an idempotent command.<br></blockquote><div><br></div><div>I agree that would be nice, though it seems that coming up with a command that covers the general case of 'make this tree look like this' might be a bit tricky. I've been thinking of adding something like<br><br><div style="margin-left:40px">ensure EXPR ROOT TREE<br><br></div>with the meaning that the ensure command would first evaluate EXPR and make sure that the resulting tree is the same as TREE; if nothing matches EXPR, it would create a node according to ROOT and put TREE underneath it.<br><br></div><div>In your case, that might look like (using $s as a shorthand for /files/etc/ssh/sshd_config/)<br><br><div style="margin-left:40px">ensure $s/AllowGroups/*[. = 'sshers'] $s/AllowGroups/01 'sshers'<br></div><br></div><div>For the more general case, for example to set up a certain line in /etc/hosts ($h == /files/etc/hosts), it would be<br><br><div style="margin-left:40px">ensure $h/*[ipaddr = "192.168.0.1"] $h/01 { "ipaddr" = "192.168.0.1" } { "canonical" = "<a href="http://example.com">example.com</a>" }<br><br></div>I am not sure how usable that ultimately would be; in particular, writing down the subtree in an understandable manner seems a bit of a head scratcher.<br><br></div><div>Thinking about this some more, EXPR and ROOT both give you the root node for your subtree, and you want to be able to both set the value of that root node (as in your example) and the children of that node (as in the /etc/hosts example) so that the ensure command really would need to be<br><br><div style="margin-left:40px">ensure EXPR ROOT VALUE CHILDREN<br><br></div>where VALUE would be a string and CHILDREN would be a list of trees. We could probably have specialized variants like 'ensure_value EXPR ROOT VALUE' or some such.<br><br></div><div>Would anybody be able to use that successfully ? Would that even cover most cases where people want to idempotently set things up in the tree ?<br></div><div><br></div><div>David<br></div></div></div></div>