ini¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version2.0.
Synopsis¶
- The ini lookup reads the contents of a file in INI format C(key1=value1). This plugin retrieves the value on the right side after the equal sign C('=') of a given section C([section]).
- You can also read a property file which - in this case - does not contain section.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _terms required |
The key(s) to look up. | |
| allow_no_value bool |
Read an ini file which contains key without value and without '=' symbol. Version Added: 2.12 |
|
| case_sensitive | Whether key names read from O(file) should be case sensitive. This prevents duplicate key errors if keys only differ in case. Version Added: 2.12 |
|
| default | Return value if the key is not in the ini file. | |
| encoding | Default: utf-8 |
Text encoding to use. |
| file | Default: ansible.ini |
Name of the file to load. |
| interpolation bool |
Default: True |
Allows for interpolation of values, see https://docs.python.org/3/library/configparser.html#configparser.BasicInterpolation Version Added: 2.18 |
| re boolean |
Flag to indicate if the key supplied is a regexp. | |
| section | Default: global |
Section where to lookup the key. |
| type | Default: ini Choices: ini, properties |
Type of the file. 'properties' refers to the Java properties files. |
Examples¶
- ansible.builtin.debug: msg="User in integration is {{ lookup('ansible.builtin.ini', 'user', section='integration', file='users.ini') }}"
- ansible.builtin.debug: msg="User in production is {{ lookup('ansible.builtin.ini', 'user', section='production', file='users.ini') }}"
- ansible.builtin.debug: msg="user.name is {{ lookup('ansible.builtin.ini', 'user.name', type='properties', file='user.properties') }}"
- ansible.builtin.debug:
msg: "{{ item }}"
loop: "{{ q('ansible.builtin.ini', '.*', section='section1', file='test.ini', re=True) }}"
- name: Read an ini file with allow_no_value
ansible.builtin.debug:
msg: "{{ lookup('ansible.builtin.ini', 'user', file='mysql.ini', section='mysqld', allow_no_value=True) }}"
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _raw | list | value(s) of the key(s) in the ini file |
Authors¶
- Yannig Perre (!unknown)