# Appending options with ini\_file?

**URL:** <https://forum.ansible.com/t/appending-options-with-ini-file/12345>\
**Category:** Ansible Project\
**Created:** [February 12, 2013, 10:00pm UTC](https://forum.ansible.com/t/appending-options-with-ini-file/12345 "2013-02-12T22:00:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nolan\_Darilek](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@Nolan\_Darilek](https://forum.ansible.com/u/Nolan_Darilek)\
**Post date:** [February 12, 2013, 10:00pm UTC](https://forum.ansible.com/t/appending-options-with-ini-file/12345/1 "2013-02-12T22:00:38Z")

</div>

I'm using Ansible to create a backupninja config, which claims to be an INI. I have a default .rdiff file which specifies things like so:

[source]  
...  
include = /root  
include = /home  
include = /usr/local

and I want other tasks to add more include directives. So my mysql tasks would add:

include = /var/backups/mysql

to the [source] section.

Unfortunately, if I do:

- ini\_file: dest=/etc/backup.d/98.rdiff section=source option=include value=/var/backups/mysql

this trashes all of my other includes.

This isn't a case for lineinfile since the include needs to be in the source section.

I don't see anything about appending an option, just about setting one. And this seems to trash my other include options. What am I missing?

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 12, 2013, 10:18pm UTC](https://forum.ansible.com/t/appending-options-with-ini-file/12345/2 "2013-02-12T22:18:37Z")

</div>

There have been lots of threads about INI file lately, let's  
consolidate on one of them 🙂

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 12, 2013, 10:19pm UTC](https://forum.ansible.com/t/appending-options-with-ini-file/12345/3 "2013-02-12T22:19:35Z")

</div>

Misread this as "lineinfile", sorry.

It is probably not aware of how to do multiples.

I would strongly recommend the template module.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [February 12, 2013, 10:23pm UTC](https://forum.ansible.com/t/appending-options-with-ini-file/12345/4 "2013-02-12T22:23:53Z")

</div>

neither the spec nor most ini file implementations don't allow for  
duplicate values. Probably the parser ansible uses doesn't either  
(python's ConfigParser IIRC).

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 12, 2013, 10:35pm UTC](https://forum.ansible.com/t/appending-options-with-ini-file/12345/5 "2013-02-12T22:35:22Z")

</div>

INI really doesn't have a spec. But in this case I agree it's weird  
and don't think we have to solve it.

[http://en.wikipedia.org/wiki/INI\_file](http://en.wikipedia.org/wiki/INI_file)

Did I mention the template module was really great? 🙂

---

<div class="post-metadata">

**Author:** ![Nigel\_Metheringham](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@Nigel\_Metheringham](https://forum.ansible.com/u/Nigel_Metheringham)\
**Post date:** [February 13, 2013, 9:59am UTC](https://forum.ansible.com/t/appending-options-with-ini-file/12345/6 "2013-02-13T09:59:42Z")

</div>

On the subject of ini file parsing...

If you have a hosts entry with a comment following, the ansible parser bombs out with a stack trace.

ie  
&nbsp;&nbsp;[example]  
&nbsp;&nbsp;my.example.com # this comment makes the parser explode!

&nbsp;&nbsp;Nigel.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 13, 2013, 1:17pm UTC](https://forum.ansible.com/t/appending-options-with-ini-file/12345/7 "2013-02-13T13:17:14Z")

</div>

Would gladly take patches for this.

Please include the stack trace...

---

<div class="post-metadata">

**Author:** ![Nolan\_Darilek](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@Nolan\_Darilek](https://forum.ansible.com/u/Nolan_Darilek)\
**Post date:** [February 13, 2013, 4:40pm UTC](https://forum.ansible.com/t/appending-options-with-ini-file/12345/8 "2013-02-13T16:40:35Z")

</div>

Agreed, it's non-standard and shouldn't be handled by ini\_file; I'm just not sure what is INI and what isn't so didn't realize it.

I'm not sure how template could help here because what I have is a file, 99.rdiff, which gets created with stock content on all hosts. What I then want to do is append lines to that file if they don't exist when various plays run, adding their files to the backup locations. Right now I have a hack that assumes that include directives are at the end of the file, which should be fine as long as playbooks are the only things that touch this file, and as long as my current workflow is maintained.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 13, 2013, 4:47pm UTC](https://forum.ansible.com/t/appending-options-with-ini-file/12345/9 "2013-02-13T16:47:30Z")

</div>

This feels like the assemble module may be very good for you to  
generate that file from various plays.

Maybe check that out?
