ansible.builtin.ini – read data from a ini file
Note
This module is part of ansible-base and included in all Ansible installations. In most cases, you can use the short module name ini even without specifying the collections: keyword. Despite that, we recommend you use the FQCN for easy linking to the module documentation and to avoid conflicting with other collections that may have the same module name.
New in version 2.0: of ansible.builtin
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.
 
Parameters
| Parameter | Choices/Defaults | Configuration | Comments | 
|---|---|---|---|
|   _terms    string / required    |    The key(s) to look up   |  ||
|   default    string    |   Default: ""   |    Return value if the key is not in the ini file.   |  |
|   encoding    string    |   Default: "utf-8"   |    Text encoding to use.   |  |
|   file    string    |   Default: "ansible.ini"   |    Name of the file to load.   |  |
|   re    boolean    |   
  |    Flag to indicate if the key supplied is a regexp.   |  |
|   section    string    |   Default: "global"   |    Section where to lookup the key.   |  |
|   type    string    |   
  |    Type of the file. 'properties' refers to the Java properties files.   |  
Examples
- debug: msg="User in integration is {{ lookup('ini', 'user section=integration file=users.ini') }}"
- debug: msg="User in production  is {{ lookup('ini', 'user section=production  file=users.ini') }}"
- debug: msg="user.name is {{ lookup('ini', 'user.name type=properties file=user.properties') }}"
- debug:
    msg: "{{ item }}"
  with_ini:
    - '.* section=section1 file=test.ini re=True'
   Return Values
Common return values are documented here, the following are the fields unique to this lookup:
| Key | Returned | Description | 
|---|---|---|
|   _raw    list / elements=string    |  success |   value(s) of the key(s) in the ini file   |  
Authors
- Yannig Perre (!UNKNOWN) <yannig.perre(at)gmail.com>
 
    © 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
    https://docs.ansible.com/ansible/2.10/collections/ansible/builtin/ini_lookup.html