Template with to_ini in a loop: 'str' object has no attribute 'items'

Actually ignore what I wrote above, since the ini files have sections I think you need a more complicated template? I have one like this:

; {{ ansible_managed }}
{% if php_conf_file_proposed_sections | bool %}
{%     for php_section in php_conf_file_proposed_vars | dict2items %}
[{{ php_section.key }}]
{%         for php_variable_pair in php_section.value | dict2items %}
{%             if php_conf_file_no_extra_spaces | bool %}
{{ php_variable_pair.key }}={{ php_variable_pair.value }}
{%             else %}
{{ php_variable_pair.key }} = {{ php_variable_pair.value }}
{%             endif %}
{%         endfor %}
{%     endfor %}
{% else %}
{%     for php_conf_pair in php_conf_file_proposed_vars | ansible.builtin.dict2items %}
{%         if php_conf_file_no_extra_spaces | bool %}
{{ php_conf_pair.key }}={{ php_conf_pair.value }}
{%         else %}
{{ php_conf_pair.key }} = {{ php_conf_pair.value }}
{%         endif %}
{%     endfor %}
{% endif %}
; vim: syntax=dosini

To generate ini files from lists like this:

  - name: PHP 8.3 configuration
    version: "8.3"
    state: present
    files:
      - name: PHP 8.3 CLI configuration
        path: /etc/php/8.3/cli/php.ini
        state: present
        conf:
          apc:
            "apc.coredump_unmap": "0"
            "apc.enable_cli": "1"
            "apc.enabled": "1"
            "apc.entries_hint": "4096"
            "apc.gc_ttl": "3600"
            "apc.serializer": "php"
            "apc.shm_segments": "1"
            "apc.shm_size": "32M"
            "apc.slam_defense": "1"
            "apc.ttl": "0"
            "apc.use_request_time": "0"
          "CLI Server":
            "cli_server.color": "1"
          MySQLi:
            "mysqli.allow_local_infile": "0"
            "mysqli.allow_persistent": "1"
            "mysqli.default_port": '3306'
            "mysqli.max_links": "-1"
            "mysqli.max_persistent": "-1"
            "mysqli.reconnect": "0"
            "mysqli.default_socket": "/run/mysqld/mysqld.sock"

However when I wrote this role community.general.to_ini didn’t exist… so perhaps all the above can be ignored!

I posted some links to ini resources for Ansible here, I don’t know if these will help:

Sorry I’m too knackered tonight to help any more but if you are still stuck later this week I’m sure I could help solve it!