Ok, I have resolved this problem in the following way : I've created a variable containing a list of the lines I want (metadata_lines) I then do a lineinfile with a loop (with_items) on the contents of the variable.
I haven't tested this to be idempotent even on human intervention, but it does what we need for now, that is ensure that an XML stanza is in the right file in the right place. Thanks, Bruce On 12 February 2015 at 12:38, Bruce Becker <[email protected]> wrote: > Hi all, > > This thread has breathed some calm into me, I was about to throw a fit. I > have a similar problem which I can't seem to resolve in an idempotent way. > Long story short, I need to ensure that a stanza is in an xml file, which > is generated on the fly with some variables. I need logic that says : > If the stanza is not there, add it as the variables generate it > else if the stanza is there but is different, replace it > else > DO NOTHING ! > > I can get Ansible to do the first case, but it keeps adding lines OR I can > get Ansible to do the last case if the stanza is there, but doesn't add it > if it's not. > > Since I've been using Ansible for a while now and am - how you say ? in > love - however, as with all great relationships there are these *little* > things that you just wish would work how you want. > > I want a "linesinfile" module that works like the logic above. The > declaration "these lines should be in this file" must be kept. > > >> I generally like to use the "template" module whenever I can, as >> Ansible's ethos is generally "keep things simple" wherever possible. >> > In this case, I can't use a template (easily), because I'm making checks > on an xml file which is generated on the fly. For the curious, it's the idp > metadata of a shibboleth Identity Provider. > The only way I thought of was to fetch the file, turn it into a template, > add the relevant lines locally and then template that to the remote file. > but that seemed very contorted and too "procedural" to be idempotent. > > >> >> Lineinfile only really makes sense when there is no other way, and even >> then, sed can occasionally be an easier thing to master. I'm not a great >> fan of the module, to be honest. Others like it though, so it stays :) >> > I really like lineinfile, but the behaviour in this case is quite > frustrating. Not that I'm recommending it change, just wanted to share my > experience. > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Ansible Project" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/ansible-project/wIqs1FD9mrI/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/48147bf7-1842-4ce4-be99-059f827a9564%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/48147bf7-1842-4ce4-be99-059f827a9564%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Dr. Bruce Becker, Coordinator, South African National Grid Meraka Institute, CSIR Meiring Naude Road Pretoria 0001 South Africa +27 12 841 3746 (w) | +27 12 841-4829 (f) | +27 84 989 6169 (m) | + 39 392 622 9279 AIM/GTalk/Skype/MSN/Jabber : brucellino <https://impactstory.org/BruceBecker> -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAPkbFJ9PKzgSdELLWy910PD8%2BEePKhaTHD1t7PRA%2Bqh2jnN88g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
