ansible.builtin.ini lookup – read data from an ini file
Note
This lookup plugin is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
plugin name
ini
even without specifying the collections:
keyword.
However, we recommend you use the FQCN for easy linking to the
plugin documentation and to avoid conflicting with other collections that may have
the same lookup plugin name.
New in Ansible 2.0
Synopsis
The ini lookup reads the contents of a file in INI format
key1=value1
. This plugin retrieves the value on the right side after the equal sign'='
of a given section[section]
.You can also read a property file which - in this case - does not contain section.
Terms
Parameter |
Comments |
---|---|
The key(s) to look up. |
Parameters
Parameter |
Comments |
---|---|
Read an ini file which contains key without value and without ‘=’ symbol. Choices:
|
|
Whether key names read from Default: |
|
Return value if the key is not in the ini file. Default: |
|
Text encoding to use. Default: |
|
Name of the file to load. Default: |
|
Flag to indicate if the key supplied is a regexp. Choices:
|
|
Section where to lookup the key. Default: |
|
Type of the file. ‘properties’ refers to the Java properties files. Choices:
|
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 Value
Key |
Description |
---|---|
value(s) of the key(s) in the ini file Returned: success |