another way not as optimal as using sed like proposed by Michael is to do it via 2 tasks.
tasks 1: count the number of lines to replace (via shell module using and grep -E <regexp> | wc -l ) using register to remember the linecounted task 2: using lineinfile and with_sequence: linecounted one caveat is that with sequence does not accept a 0 count ( a potential future improvement ?) so just add 1 to the count (you do not care about doing it one more time) then you can run those 2 tasks multiples times works for me on grub.conf 2014/1/4 Michael DeHaan <[email protected]> > It seems you would just use the shell module and invoke sed. > > > > On Sat, Jan 4, 2014 at 1:04 AM, eskhool <[email protected]>wrote: > >> Hi, >> If we don't have the option to use templates as the file may vary across >> system, is there a way to find and replace multiple lines based on a >> regex...something like an option in lineinfile such as 'all'. What other >> mechanism can be recommended? Any reason to not have this option? And if >> contributed will such a change be accepted in ansible core? >> >> Thanks >> >> -- >> 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. >> > > > > -- > Michael DeHaan <[email protected]> > CTO, AnsibleWorks, Inc. > http://www.ansibleworks.com/ > > -- > 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.
