Ansible ini_file module: Replace whole section

ansible

As far as I understand the documentation, I can use the ini_file module to replace a whole section of an ini file by just specifying the section value and omitting the option value:

- name: 'Set realms'
  ini_file:
    path: '/etc/krb5.conf'
    section: 'realms'
    value: |
      EXAMPLE.COM = {
        admin_server = adm.example.com
        kdc = kdc.example.com
      }

which should result in

[realms]
EXAMPLE.COM = {
  admin_server = adm.example.com
  kdc = kdc.example.com
}

removing the original contents of section [realms]. However, this results in

[realms]
None = EXAMPLE.COM = {
  admin_server = adm.example.com
  kdc = kdc.example.com
}

while also not removing the original contents of the section.

Have I misunderstood the documentation? And if yes, is there another way to achieve this?

Best Answer

@Rocreex actually you didn't define option key.

- name: 'Set realms'
  ini_file:
    path: '/tmp/krb5.conf'
    section: 'realms'
    option: ' EXAMPLE.COM'
    value: | 
      ' {
         kdc = kerberos.example.com
         admin_server = kerberos.example.com
       } '