# Module for managing comment delimited sections in configuration files?

**URL:** <https://forum.ansible.com/t/module-for-managing-comment-delimited-sections-in-configuration-files/21823>\
**Category:** Ansible Project\
**Created:** [June 21, 2016, 2:16pm UTC](https://forum.ansible.com/t/module-for-managing-comment-delimited-sections-in-configuration-files/21823 "2016-06-21T14:16:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan\_Langford](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@Alan\_Langford](https://forum.ansible.com/u/Alan_Langford)\
**Post date:** [June 21, 2016, 2:16pm UTC](https://forum.ansible.com/t/module-for-managing-comment-delimited-sections-in-configuration-files/21823/1 "2016-06-21T14:16:36Z")

</div>

I have a couple of situations where there are informal sections in a configuration file that are delimited by comments, and I’d like to update these with Ansible. Is there a module for this?

For example, the file some.cfg looks like this:

# this is the some.cfg file

var1=1  
var2=2

# some section start

svar1=1  
svar2=2

# some section end

var3=3

I want to be able to replace the variables delimited by “some section start” and “some section end”. This is complicated by the fact that the delimiters are created ad-hoc by application developers, so there’s no consistent syntax.

I can’t assemble the file from components because users can take actions that cause the file to change, so there’s no master copy.

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [June 22, 2016, 8:10pm UTC](https://forum.ansible.com/t/module-for-managing-comment-delimited-sections-in-configuration-files/21823/2 "2016-06-22T20:10:19Z")

</div>

Hi Alan,

If you want to manage blocks of text, take a look at blockinfile. You can use insertafter/insertbefore with a regex statement to look for the comment lines. Blockinfile also includes a marker that you can place at the beginning and end of a bock of Ansible-managed text. Just make sure each marker you use is uniquely named, or the block will be overwritten with subsequent writes to a block with the same marker.
