title: Which module to use to edit files - Ansible
body: <p>I want to edit the configuration file of telegraf(system metrics collecting agent).</p>
  
  <p>Telegraf comes in with a default config file which can be edited. There are many input and output plugins defined in there, which are commented out and can be added by removing the comments and also be customized.</p>
  
  <p>I want to edit only some of the plugins defined there, not all of them. For example, consider this is the file,</p>
  
  <pre><code>[global]
    interval='10s'
  
  [outputs.influxdb]
    host=['http://localhost:8086']
  
  #[outputs.elasticsearch]
  #  host=['http://localhost:9200']
  
  [inputs.netstat] 
    interface='eth0'
  </code></pre>
  
  <p>Now, I want to edit the 3 blocks, <code>global</code>, <code>outputs.influxdb</code> and <code>inputs.netstat</code>. I don't want to edit <code>outputs.elasticsearch</code> but also want that the block <code>outputs.elasticsearch</code> should remain in the file.</p>
  
  <p>When Using Ansible, I firstly used Template module, but if I use that, then the commented data would be lost.</p>
  
  <p>Then I used the ini_file module, instead of editing the already present block, it adds a new block even if it is already present, and results in something like this, </p>
  
  <pre><code>[outputs.influxdb]
   host=[http://localhost:8086]
  [outputs.influxdb]
   host=[http://xx.xx.xx.xx:8086]
  </code></pre>
  
  <p>Which module is ideal for my scenario ?</p>