Replace a string in multiple lines in a file not working

284 views
Skip to first unread message

Uppara venkat

unread,
Feb 14, 2020, 3:27:57 AM2/14/20
to ansible...@googlegroups.com
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:
      - "{{ result.files }}"  

The file of content is as below:

#Install
#-------
-fileOverwrite_D\:\\UCMDB\\UCMDBServer\\UninstallerData\\Uninstall_UCMDBServer.lax=Yes
-fileOverwrite_D\:\\UCMDB\\UCMDBServer\\UninstallerData\\resource\\iawin64_x64.dll=Yes
-fileOverwrite_D\:\\UCMDB\\UCMDBServer\\UninstallerData\\resource\\iawin32.dll=Yes
-fileOverwrite_D\:\\UCMDB\\UCMDBServer\\UninstallerData\\resource\\win64_32_x64.exe=Yes
-fileOverwrite_D\:\\UCMDB\\UCMDBServer\\UninstallerData\\resource\\remove.exe=Yes
-fileOverwrite_D\:\\UCMDB\\UCMDBServer\\UninstallerData\\resource\\invoker.exe=Yes
-fileOverwrite_D\:\\UCMDB\\UCMDBServer\\tools\\server\\custom-install.jar=Yes
-fileOverwrite_D\:\\UCMDB\\UCMDBServer\\content\\probe_patch\\probe-patch-11.4-windows.zip=Yes
-fileOverwrite_E\:\\UCMDB\\UCMDBServer\\content\\probe_installer\\UCMDB_DataFlowProbe_11.4.exe=Yes

I run the playbook it reflecting only last line of a file. 

Can you help me how to resolve this issue?

--
Thanks& Regards,
Venkat

Tabrez Nazir

unread,
Feb 14, 2020, 3:48:06 AM2/14/20
to ansible...@googlegroups.com
Hi Venkat,

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: '# \1'


--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAFMhZ_J-9%2BwPxUSJ5k%2B%2B%2Bfnxu%2BhVg%3DRpT_DaSMuSHHNiG4oOVA%40mail.gmail.com.

Uppara venkat

unread,
Feb 14, 2020, 4:39:39 AM2/14/20
to ansible...@googlegroups.com
Thanks for reply.
I'm working on windows so it's not working "replace module" 




--






Thanks& Regards,
venkatesulu.U
8147041026

Stefan Hornburg (Racke)

unread,
Feb 14, 2020, 4:50:38 AM2/14/20
to ansible...@googlegroups.com
On 2/14/20 10:39 AM, Uppara venkat wrote:
> Thanks for reply.
> I'm working on windows so it's not working "replace module" 
>

Why wouldn't the module work on Windows?

Regards
Racke
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> <https://groups.google.com/d/msgid/ansible-project/CAFMhZ_J-9%2BwPxUSJ5k%2B%2B%2Bfnxu%2BhVg%3DRpT_DaSMuSHHNiG4oOVA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAF_FPv_DZd81c%2B%2BDVw6_zEJR0UVmBKcaySxur%3DethL%2BY9XAR9g%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAF_FPv_DZd81c%2B%2BDVw6_zEJR0UVmBKcaySxur%3DethL%2BY9XAR9g%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
>
>
> --
>
>
>
>
>
>
> Thanks& Regards,
> venkatesulu.U
> 8147041026
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAFMhZ_%2BErzEPkVcyki5vm%3DFiV_7z9gnEVXTFdLLkxHxC_tvp1w%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAFMhZ_%2BErzEPkVcyki5vm%3DFiV_7z9gnEVXTFdLLkxHxC_tvp1w%40mail.gmail.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Uppara venkat

unread,
Feb 14, 2020, 5:15:44 AM2/14/20
to ansible...@googlegroups.com
All modules not supporting for windows.

see below link for windows for window;

To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8d142612-99de-00e1-b694-d2dc7a7839ef%40linuxia.de.

Stefan Hornburg (Racke)

unread,
Feb 14, 2020, 5:19:36 AM2/14/20
to ansible...@googlegroups.com
On 2/14/20 11:15 AM, Uppara venkat wrote:
> All modules not supporting for windows.
>
> see below link for windows for window;
> https://docs.ansible.com/ansible/latest/modules/list_of_windows_modules.html 

I would assume that all regular Ansible modules work with Windows unless specifically noted in
the module documentation.

Regards
Racke

>
> On Fri, Feb 14, 2020 at 3:20 PM Stefan Hornburg (Racke) <ra...@linuxia.de <mailto:ra...@linuxia.de>> wrote:
>
> On 2/14/20 10:39 AM, Uppara venkat wrote:
> > Thanks for reply.
> > I'm working on windows so it's not working "replace module" 
> >
>
> Why wouldn't the module work on Windows?
>
> Regards
>          Racke
> >
> > On Fri, Feb 14, 2020 at 2:17 PM Tabrez Nazir <tabrez.na...@gmail.com <mailto:tabrez.na...@gmail.com>
> <mailto:tabrez.na...@gmail.com <mailto:tabrez.na...@gmail.com>>> wrote:
> >
> >     Hi Venkat,
> >
> >     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: '#\1'
> >
> >
> >
> >     On Fri, Feb 14, 2020, 13:57 Uppara venkat <venkate...@gmail.com <mailto:venkate...@gmail.com>
> >         ansible-proje...@googlegroups.com <mailto:ansible-project%2Bunsu...@googlegroups.com>
> <mailto:ansible-proje...@googlegroups.com <mailto:ansible-project%2Bunsu...@googlegroups.com>>.
> >         To view this discussion on the web visit
> >       
>  https://groups.google.com/d/msgid/ansible-project/CAFMhZ_J-9%2BwPxUSJ5k%2B%2B%2Bfnxu%2BhVg%3DRpT_DaSMuSHHNiG4oOVA%40mail.gmail.com
> >       
>  <https://groups.google.com/d/msgid/ansible-project/CAFMhZ_J-9%2BwPxUSJ5k%2B%2B%2Bfnxu%2BhVg%3DRpT_DaSMuSHHNiG4oOVA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> >
> >     --
> >     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
> >     ansible-proje...@googlegroups.com <mailto:ansible-project%2Bunsu...@googlegroups.com>
> <mailto:ansible-proje...@googlegroups.com <mailto:ansible-project%2Bunsu...@googlegroups.com>>.
> >     To view this discussion on the web visit
> >   
>  https://groups.google.com/d/msgid/ansible-project/CAF_FPv_DZd81c%2B%2BDVw6_zEJR0UVmBKcaySxur%3DethL%2BY9XAR9g%40mail.gmail.com
> >   
>  <https://groups.google.com/d/msgid/ansible-project/CAF_FPv_DZd81c%2B%2BDVw6_zEJR0UVmBKcaySxur%3DethL%2BY9XAR9g%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> >
> >
> >
> > --
> >
> >
> >
> >
> >
> >
> > Thanks& Regards,
> > venkatesulu.U
> > 8147041026
> >
> > --
> > 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
> > ansible-proje...@googlegroups.com <mailto:ansible-project%2Bunsu...@googlegroups.com>
> <mailto:ansible-proje...@googlegroups.com <mailto:ansible-project%2Bunsu...@googlegroups.com>>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/ansible-project/CAFMhZ_%2BErzEPkVcyki5vm%3DFiV_7z9gnEVXTFdLLkxHxC_tvp1w%40mail.gmail.com
> >
> <https://groups.google.com/d/msgid/ansible-project/CAFMhZ_%2BErzEPkVcyki5vm%3DFiV_7z9gnEVXTFdLLkxHxC_tvp1w%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-project%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAFMhZ_JyNikOkODfnFvQCgYCD9NxyFWi2Wz7VfyKS531cJSjdw%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAFMhZ_JyNikOkODfnFvQCgYCD9NxyFWi2Wz7VfyKS531cJSjdw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
signature.asc

Uppara venkat

unread,
Feb 14, 2020, 5:26:10 AM2/14/20
to ansible...@googlegroups.com
Ansible is easy in linux but not easy in windows.

To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6c863637-b20c-07bf-bad3-1c5a84d0a01e%40linuxia.de.
Reply all
Reply to author
Forward
0 new messages