Ansible ini_file module does not create sections when no options specified

ansibleconfigurationconfiguration-management

I use Ansible to build configuration files in ini format. When I use the ini_file module with option and value pair it works as expected, for example:

- name: Create configuration file
  ini_file:
    path: /tmp/test.conf
    state: present
    section: lol
    option: foo
    value: bar

Would result with:

[lol]
foo = bar

However I want a specific section to exist without options in it, like so:

- name: Create configuration file
  ini_file:
    path: /tmp/test.conf
    state: present
    section: lol

But all it does is reporting ok on the task and moves on to the next one.

When I use verbose mode I can see: ok: [localhost] => {"changed": false, "msg": "OK", "path": "/tmp/test.conf", "state": "absent"}

How can I use the module to create option-less sections?

Best Answer

ini is an informal standard, but from my understanding there isn't much sense in a section without an option. That would be my first guess why this isn't implemented in Ansible.

Rather then using the ini-Module I would suggest to use the lineinfile module to ensure that a section is present in a ini file.