Author: | Jan-Piet Mens |
---|
Manage (add, remove, change) individual settings in an INI-style file without having to manage the file as a whole with, say, template or assemble. Adds missing sections if they don’t exist. Comments are discarded when the source file is read, and therefore will not show up in the destination file.
parameter | required | default | choices | comments |
---|---|---|---|---|
backup | no | no |
|
Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly. |
dest | yes | Path to the INI-style file; this file is created if required | ||
option | no | if set (required for changing a value), this is the name of the option.May be omitted if adding/removing a whole section. | ||
others | no | all arguments accepted by the file module also work here | ||
section | yes | Section name in INI file. This is added if state=present automatically when a single value is being set. |
||
value | no | the string value to be associated with an option. May be omitted when removing an option. |
Note
Requires ConfigParser
# Ensure "fav=lemonade is in section "[drinks]" in specified file
- ini_file: dest=/etc/conf section=drinks option=fav value=lemonade mode=0600 backup=yes
- ini_file: dest=/etc/anotherconf
section=drinks
option=temperature
value=cold
backup=yes
Note
While it is possible to add an option without specifying a value, this makes no sense.
Note
A section named default cannot be added by the module, but if it exists, individual options within the section can be updated. (This is a limitation of Python’s ConfigParser.) Either use template to create a base INI file with a [default] section, or use lineinfile to add the missing line.