If it's an INI file, then your specific requirements can be probably met by ini_file
module (http://docs.ansible.com/ini_file_module.html).
If your change is limited just few lines (or eve one), then you can probably look at lineinfile
module (http://docs.ansible.com/lineinfile_module.html).
Should you however need to change large number of settings, then it may be more beneficial to use template
(http://docs.ansible.com/template_module.html) or assemble
(http://docs.ansible.com/assemble_module.html). The main disadvantage of this approach is that you may need to review your template or fragments when updating your dependency.