�
�Udac @` s� d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d Z d d
l Z d d
l
Z
d d
l Z d d
l Z d d l
m Z d � Z d
� Z d
d
d
d e e e e d � Z d � Z e d k r� e � n d
S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust communityt supported_bys
---
module: ini_file
short_description: Tweak settings in INI files
extends_documentation_fragment: files
description:
- Manage (add, remove, change) individual settings in an INI-style file without having
to manage the file as a whole with, say, M(template) or M(assemble).
- Adds missing sections if they don't exist.
- Before Ansible 2.0, comments are discarded when the source file is read, and therefore will not show up in the destination file.
- Since Ansible 2.3, this module adds missing ending newlines to files to keep in line with the POSIX standard, even when
no other modifications need to be applied.
version_added: "0.9"
options:
path:
description:
- Path to the INI-style file; this file is created if required.
- Before Ansible 2.3 this option was only usable as I(dest).
type: path
required: true
aliases: [ dest ]
section:
description:
- Section name in INI file. This is added if C(state=present) automatically when
a single value is being set.
- If left empty or set to C(null), the I(option) will be placed before the first I(section).
- Using C(null) is also required if the config format does not support sections.
type: str
required: true
option:
description:
- If set (required for changing a I(value)), this is the name of the option.
- May be omitted if adding/removing a whole I(section).
type: str
value:
description:
- The string value to be associated with an I(option).
- May be omitted when removing an I(option).
type: str
backup:
description:
- Create a backup file including the timestamp information so you can get
the original file back if you somehow clobbered it incorrectly.
type: bool
default: no
state:
description:
- If set to C(absent) the option or section will be removed if present instead of created.
type: str
choices: [ absent, present ]
default: present
no_extra_spaces:
description:
- Do not insert spaces before and after '=' symbol.
type: bool
default: no
version_added: "2.1"
create:
description:
- If set to C(no), the module will fail if the file does not already exist.
- By default it will create the file if it is missing.
type: bool
default: yes
version_added: "2.2"
allow_no_value:
description:
- Allow option without value and without '=' symbol.
type: bool
default: no
version_added: "2.6"
notes:
- While it is possible to add an I(option) without specifying a I(value), this makes no sense.
- As of Ansible 2.3, the I(dest) option has been changed to I(path) as default, but I(dest) still works as well.
author:
- Jan-Piet Mens (@jpmens)
- Ales Nosek (@noseka1)
s�
# Before Ansible 2.3, option 'dest' was used instead of 'path'
- name: Ensure "fav=lemonade is in section "[drinks]" in specified file
ini_file:
path: /etc/conf
section: drinks
option: fav
value: lemonade
mode: '0600'
backup: yes
- name: Ensure "temperature=cold is in section "[drinks]" in specified file
ini_file:
path: /etc/anotherconf
section: drinks
option: temperature
value: cold
backup: yes
N( t
AnsibleModulec C` sO t j | � } t j d | | � pN t j d | | � pN t j d | | � S( Ns ( | )*%s( | )*(=|$)s #( | )*%s( | )*(=|$)s ;( | )*%s( | )*(=|$)( t ret escapet match( t optiont line( ( sB /usr/lib/python2.7/site-packages/ansible/modules/files/ini_file.pyt match_opt{ s c C` s# t j | � } t j d | | � S( Ns ( | )*%s( | )*(=|$)( R R
R ( R R
( ( sB /usr/lib/python2.7/site-packages/ansible/modules/files/ini_file.pyt match_active_opt� s t presentc
C` s� t d d d d d d | d d | � }
t j j | � s� | s^ | j d d d d
| � n t j j | � } t j j | � r� | j r� t j | � n g } n- t | d � }
z |
j � } Wd |
j
� X| j r� d j | � |
d <n t
} | s| j d � n | d
d k s2| d
d
d k rK| d
c d 7<t } n d } | j d d | � | j d � | s�| } n | } d } d } | r�d } n d } xIt | � D];\ } } | j d | � r�t } | } q�| j d � r�| r�| d k r�x� t | d d
� D]n } t j d | | d � s| r\| r\| j | d | � n | j | | | | f � d } t } PqqWn, | d k r�| r�| | | 5d } t } n Pq�q�| r�| r�| d k r�t | | � r�| r| rd | } n | | | f } | | | k } | p*| } | r<d } n | | | <| r�| d } xY | t | � k r�| | } | j d � r�Pn t | | � r�| | =qY| d } qYWn Pq�q�| d k r�t | | � r�| | =t } d } Pq�q�q�q�W| d =| d
3| rt| rt| d k rt| j d | � | rN| rN| j d | � n | j | | | f � t } d } n | j r�d j | � |
d <n d } | r�| j r�| r�| j | � } n yH t j d | j � \ } } t j | d � } | j | � | j
� Wn- t k
r8| j d d! d"