The one way i know of is either just use shell/command and use sed, or break this into tasks, the first counts and registers the line needs to be replaced again using shell/cmd "grep", and the second does the lineinfile per item using "with_sequence" and remember to add +1 to the number counted as sequence does not accept 0 count
This was mentioned before in the list On 6 February 2014 23:02, Jeff Geerling <[email protected]> wrote: > I'm trying to make my lineinfile command that uses multiple lines > idempotent: > > - lineinfile: > > dest=/etc/example.conf > regexp='^\[test(.*)' > line='[test]{{ '\n' }}secondline' > > I've tried this, and the following regexp variations: > > regexp=''/^\[test(.*)/s' # trying to get it to work multiline > regexp='^\[test\]{{ '\n' }}secondline' # trying to use same pattern in > 'line' > > I've also tried a bunch of other variations, with no luck, as well as > adding 'insertafter=EOF'. In all cases, I ended up getting another block of > text each time I ran ansible-playbook. > > How can I do a lineinfile with multiple lines with idempotence? > > (Also, I can't get the line to work without wrapping newlines, tab > characters, etc. in a variable reference ({{ }}), though I've seen other > examples online where those whitespace characters must be working correctly. > > -- > 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]. > For more options, visit https://groups.google.com/groups/opt_out. > -- 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]. For more options, visit https://groups.google.com/groups/opt_out.
