I have come across a peculiar issue while using ansible. The problem is very strange and dangerous. I have a written a code to insert data in a particular section of a file i.e to add line after [database] in say /etc/cinder/cinder.conf.The problem is I have noticed sometimes it adds the content properly after the tag [database] , but sometimes it gets confused by seeing a line like # put ur infore here for [database]  in the file and adds our required line below it instead of where it should actually put it.   - name: Adding Entries in /etc/cinder/cinder.conf     lineinfile:      dest: /etc/cinder/cinder.conf      insertafter:  {{ item.inserts }}      state: present      line: {{ item.lines }}     with_items:      - { inserts: '\[database\]', lines: 'rpc_backend = rabbit' }This situation is quite dangerous in a production environment! How can I add the data correctly?
inserting data into a particular section of a configuration file with ansible
text processing;configuration;ansible
To avoid matching in a comment, anchor your regexp to the beginning of the line:- { inserts: '^\[database\]', lines: 'rpc_backend = rabbit' }