ansible.builtin.ini (v2.16.5) — lookup

read data from an ini file

| "added in version" 2.0 of ansible.builtin"

Authors: Yannig Perre (!UNKNOWN) <yannig.perre(at)gmail.com>

Install Ansible via pip

Install with pip install ansible-core==2.16.5

Description

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.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- ansible.builtin.debug: msg="User in integration is {{ lookup('ansible.builtin.ini', 'user', section='integration', file='users.ini') }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- ansible.builtin.debug: msg="User in production  is {{ lookup('ansible.builtin.ini', 'user', section='production',  file='users.ini') }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- ansible.builtin.debug: msg="user.name is {{ lookup('ansible.builtin.ini', 'user.name', type='properties', file='user.properties') }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- ansible.builtin.debug:
    msg: "{{ item }}"
  loop: "{{ q('ansible.builtin.ini', '.*', section='section1', file='test.ini', re=True) }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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) }}"

Inputs

    
re:
    default: false
    description: Flag to indicate if the key supplied is a regexp.
    type: boolean

file:
    default: ansible.ini
    description: Name of the file to load.

type:
    choices:
    - ini
    - properties
    default: ini
    description: Type of the file. 'properties' refers to the Java properties files.

_terms:
    description: The key(s) to look up.
    required: true

default:
    default: ''
    description: Return value if the key is not in the ini file.

section:
    default: global
    description: Section where to lookup the key.

encoding:
    default: utf-8
    description: Text encoding to use.

allow_no_value:
    aliases:
    - allow_none
    default: false
    description:
    - Read an ini file which contains key without value and without '=' symbol.
    type: bool
    version_added: '2.12'
    version_added_collection: ansible.builtin

case_sensitive:
    default: false
    description: 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'
    version_added_collection: ansible.builtin

Outputs

_raw:
  description:
  - value(s) of the key(s) in the ini file
  elements: str
  type: list

See also