Hi all,
I’m written a play book to replace a string in multiple lines in a file but it not reflected, It has changed in last line of a file.
not replace in multiple places.
name: updating driver letter as in config file
win_lineinfile:
path: “{{ item.path }}”
backrefs: true
regexp: ‘-fileOverwrite_D’
line: ‘-fileOverwrite_{{ target_disk|upper }}’
state: present
with_items:
Use replace instead of line. Replace will substitute all instances of regexp.
See example below:
- name: Replace after the expression till the end of the file (requires Ansible >= 2.4)
replace:
path: /etc/apache2/sites-available/default.conf
after: 'NameVirtualHost [*]'
regexp: '^(.+)$'
replace: '# '