Find Regexp and replace expression for CSV file starting with $
<p>I need an Regexp and Replace expression to capture contents from CSV file. My CSV file starts like this.</p>

<p>Example- expression should find key name "FC_host" in my CSV file and replace with different value.</p>

<pre><code>$TH_appName=tuipatthcrfh3320
#$TH_host=10.145.129.75
$TH_host=10.145.129.75
$TH_casPort=8500;
$TH_eacPort=8888;
$FC_appName=tuipatfc3320;
#$FC_host=10.145.129.75
$FC_host=10.145.129.75
$FC_casPort=8500;
$FC_eacPort=8888;
</code></pre>

<p>Below is my code. This code works but has few issues.Kindly help me on this.Moreover I am using regexp and replace so that I need to update them in remote server.</p>

<pre><code>    ---
  - hosts: local
    vars:
      properties:
      - { name: "TH_appName", value: "10.0.1" }
    tasks:
      - name: Find and Replace
        replace:
          dest: /etc/ansible/kalyan-tui/example.csv
          regexp: '(.*){{ item.name }}=(.*);'
          replace: '\1{{ item.name }}={{ item.value }};'
         # state: present
        with_items:
          - "{{ properties }}"
</code></pre>

<p>The task should look like this:</p>

<pre><code>- name: Find and Replace
  replace:
    dest: /etc/ansible/kalyan-tui/example.csv
    regexp: ^\$FC_host=.*
    replace: "$FC_host={{ new_value }}"
</code></pre>

<hr>

<ul>
<li><code>state</code> is not a parameter of <code>replace</code></li>
<li>variable name cannot contain spaces </li>
<li>you don't need to quote the <code>regexp</code> value</li>
<li>you don't need to escape dollar sign in the replacement value</li>
</ul>

python ansible ansible-playbook ansible-2.x