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 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/48147bf7-1842-4ce4-be99-059f827a9564%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
