Replace should substitute all instance matching the regexp, as for the 
manual 

This module will replace all instances of a pattern within a file.
Try this

- hosts: localhost
  tasks:
  - name: sort out blank discrepancy
    replace: 

   path: resolv.conf
   regexp: '^(.*)\s+#\s+(.*)$'
   replace: '\1 # \2'
   backup: yes

  - name: remove block regexps
    blockinfile:
      path: "./resolv.conf"
      marker: "{mark}"
      marker_begin: "nameserver 13.2.7.8 #dns"
      marker_end: "search eu.ro.net mrtools.ro.com mit.gbr.ro.com"
      state: absent
      backup: yes

Anyway I didn't test it yet.
Regards 

Luca 

Il giorno mercoledì 27 febbraio 2019 17:26:41 UTC+1, Deepan M ha scritto:
>
> Hello Luca,
>
>   Replace can be removed single line, but how we can remove block ?
>
> Thanks,
> Deepan M
>
> On Wednesday, February 27, 2019 at 9:18:48 PM UTC+5:30, fusillator wrote:
>>
>> Consider using the replace module to normalize the space incongruence 
>> before the blockinfile task.. 
>> Something like
>>
>> - replace:
>>     path: resolv.conf
>>     regexp: '^(.*)\s+#\s+(.*)$'
>>     replace: '\1 # \2'
>>     backup: yes
>>
>> unfortunately I can't try the playbook in this moment. 
>>
>> Regards
>>
>> Luca
>>
>>
>>
>>

-- 
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/41cc72b3-978f-4398-9415-95a94144cc2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to