Hello Luca,
Below playbook no result, seems because of #name its not working i guess.
---
- hosts: TC2
become: yes
tasks:
- name: copy the file
shell: cp -p /tmp/resolv.conf /tmp/resolv.conf.$(date +%F_%R)
- name: remove block lines
replace: dest=/tmp/resolv.conf regexp='{{ item.line }}' replace='{{
item.rep }}'
with_items:
- { line: '^nameserver 13.2.7.8 # dns1', rep: '' }
- { line: '^nameserver 13.2.7.9 # dns2', rep: '' }
- { line: 'nameserver 13.2.7.10 # dns3', rep: '' }
- { line: 'search eu.ro.net mrtools.ro.com mit.gbr.ro.com', rep: ''}
*:-Below playbook is working but not deleting the entire line, example the
nameserver 13.2.7.8 # dns1, "nameserver 13.2.7.8" is getting deleted
but # dns1 still persist in file! *
---
- hosts: TC2
become: yes
tasks:
- name: copy the file
shell: cp -p /tmp/resolv.conf /tmp/resolv.conf.$(date +%F_%R)
- name: remove block lines
replace: dest=/tmp/resolv.conf regexp='{{ item.line }}' replace='{{
item.rep }}'
with_items:
- { line: '^nameserver 13.2.7.8', rep: '' }
- { line: '^nameserver 13.2.7.9', rep: '' }
- { line: 'nameserver 13.2.7.10', rep: '' }
- { line: 'search eu.ro.net mrtools.ro.com mit.gbr.ro.com', rep: ''}
Thanks,
Deepan M
On Wednesday, February 27, 2019 at 9:56:41 PM UTC+5:30, Deepan M wrote:
>
> 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/c2bbc384-ddae-4d18-baf5-f78d69a2d67d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.