Question on win_lineinfile replace/deleting the values with-in config file

50 views
Skip to first unread message

Kumaresh kulal

unread,
May 11, 2020, 6:45:23 AM5/11/20
to Ansible Project
Hello,

I have got a task to configure the config file by removing the not required text from the config file. 

Sample Config File:

<?xml version="1.0" encoding="utf-8" ?>
  <variable name="WorkflowLoggingDirectory" value="${specialfolder:folder=LocalApplicationData}" />
  <rules>
    <logger name="WorkflowLogging" writeTo="WorkflowLogFiles" final="true" />
    <logger minLevel="Info" writeTo="EventLog" />
  </rules>
  <targets>
    <target type="File" name="WorkflowLogFiles" fileName="${WorkflowLoggingDirectory}/${shortdate}_Execution.log" layout="${time} ${level} ${message}" concurrentWrites="true" encoding="utf-8" writeBom="true" />
    <target type="EventLog" name="EventLog" layout="${processname} ${assembly-version} ${newline}${message}" log="Application" />
  </targets>
</nlog>

Text to Remove: ${time} ${level} 

So far I was able to do this using the below win_lineinfile playbook and it works fine:

---

- hosts: all

  tasks:

   - name: updating content in config file

     win_lineinfile:

       dest: C:\tmp\NLog.config

       regexp: '^(.*)time(.*)$'

       line: '    <target type="File" name="WorkflowLogFiles" fileName="${WorkflowLoggingDirectory}/${shortdate}_Execution.log" layout="${message}" concurrentWrites="true" encoding="utf-8" writeBom="true" />'

       backrefs: yes


I would like to know if there is a better way to handle this instead of re-writing the whole line, can I only replace/delete the portion of the text?



Thank You :-)


Kumar

Stefan Hornburg (Racke)

unread,
May 11, 2020, 7:16:48 AM5/11/20
to ansible...@googlegroups.com
Lineinfile doesn't make sense for XML files, use (win_)xml module.

Regards
Racke

>
>
> Thank You :-)
>
>
> Kumar
>
> --
> 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/ea6a7f82-5896-4d02-a6a3-5401f0821139%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/ea6a7f82-5896-4d02-a6a3-5401f0821139%40googlegroups.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
Reply all
Reply to author
Forward
0 new messages