# Question on win\_lineinfile replace/deleting the values with-in config file

**URL:** <https://forum.ansible.com/t/question-on-win-lineinfile-replace-deleting-the-values-with-in-config-file/32905>\
**Category:** Ansible Project\
**Created:** [May 11, 2020, 10:45am UTC](https://forum.ansible.com/t/question-on-win-lineinfile-replace-deleting-the-values-with-in-config-file/32905 "2020-05-11T10:45:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kumaresh\_kulal](https://avatars.discourse-cdn.com/v4/letter/k/3bc359/32.png) [@Kumaresh\_kulal](https://forum.ansible.com/u/Kumaresh_kulal)\
**Post date:** [May 11, 2020, 10:45am UTC](https://forum.ansible.com/t/question-on-win-lineinfile-replace-deleting-the-values-with-in-config-file/32905/1 "2020-05-11T10:45:22Z")

</div>

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" ?\>

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

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

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [May 11, 2020, 11:16am UTC](https://forum.ansible.com/t/question-on-win-lineinfile-replace-deleting-the-values-with-in-config-file/32905/2 "2020-05-11T11:16:16Z")

</div>

> 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" ?\>  
> \<nlog xmlns="[http://www.nlog-project.org/schemas/NLog.xsd&quot](http://www.nlog-project.org/schemas/NLog.xsd&quot); xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance&quot;&gt](http://www.w3.org/2001/XMLSchema-instance&quot;&gt);  
> \<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: &#39;^\(\.\*\)time\(\.\*\)$&#39;
> 
> line: &#39; &lt;target type=&quot;File&quot; name=&quot;WorkflowLogFiles&quot;
> 
> ```
> 
> 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?

Lineinfile doesn't make sense for XML files, use (win\_)xml module.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
