# Idempontent maintenance of a cfg file

**URL:** <https://forum.ansible.com/t/idempontent-maintenance-of-a-cfg-file/19423>\
**Category:** Ansible Project\
**Created:** [October 2, 2015, 10:03pm UTC](https://forum.ansible.com/t/idempontent-maintenance-of-a-cfg-file/19423 "2015-10-02T22:03:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason3](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@Jason3](https://forum.ansible.com/u/Jason3)\
**Post date:** [October 2, 2015, 10:03pm UTC](https://forum.ansible.com/t/idempontent-maintenance-of-a-cfg-file/19423/1 "2015-10-02T22:03:48Z")

</div>

Hi All,

I’m learning Ansible and am preparing to try and execute both deployment and configuration maintenance on a few systems at work.

One configuration file in particular is giving me issues however. I want to be able to update Min and Max Instances in this section of a cfg file:

`

…  
[PSAPPSRV]  
;=========================================================================  
; Settings for PSAPPSRV  
;=========================================================================

;-------------------------------------------------------------------------  
; UBBGEN settings  
Min Instances=25  
Max Instances=25  
Service Timeout=300

;-------------------------------------------------------------------------  
; Number of services after which PSAPPSRV will automatically restart.  
…

`

The problem is the file also contains other sections with identical Min/Max lines like this:

`

…  
[PSQRYSRV]  
;=========================================================================  
; Settings for PSQRYSRV  
;=========================================================================

;-------------------------------------------------------------------------  
; UBBGEN settings  
Min Instances=6  
Max Instances=6  
Service Timeout=1200

;-------------------------------------------------------------------------  
; Number of services after which PSQRYSRV will automatically restart.  
…

`

I want to be able to run an ansible task repeatedly against this file to update the Min/Max lines only if changed. I don’t want to use the template or shell modules because if the lines are changed, I need to initiate a restart of the dependent services and I don’t want to do that unnecessarily. I also want to have some sort of record of the file being changed via the ansible-playbook output.

I’ve looked into lineinfile module, but have yet to find a way to only update a single line number. I looked into sed with ansible variables, but again, that doesn’t meet the idempotent requirement.

Is there any way to achieve what i’m looking for here?

Thanks,  
Jason

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 2, 2015, 11:43pm UTC](https://forum.ansible.com/t/idempontent-maintenance-of-a-cfg-file/19423/2 "2015-10-02T23:43:01Z")

</div>

template would not force unnecessary changes, it is your best bet for  
idempotency.

---

<div class="post-metadata">

**Author:** ![Jason3](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@Jason3](https://forum.ansible.com/u/Jason3)\
**Post date:** [October 3, 2015, 12:54am UTC](https://forum.ansible.com/t/idempontent-maintenance-of-a-cfg-file/19423/3 "2015-10-03T00:54:31Z")

</div>

Ahh ok, I see. I didn’t realize templates did comparisons before copying. Thanks for your help!
