arillso.system.to_toml filter – Convert variable to TOML string

Note

This filter plugin is part of the arillso.system collection (version 1.0.5).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install arillso.system. You need further requirements to be able to use this filter plugin, see Requirements for details.

To use it in a playbook, specify: arillso.system.to_toml.

New in arillso.system 1.0.0

Synopsis

  • Converts an Ansible variable (dict) into a TOML string representation.

  • This filter uses the tomli-w library (or toml as fallback) for writing TOML.

  • For reading TOML, use the companion filter from_toml.

Requirements

The below requirements are needed on the local controller node that executes this filter.

  • tomli-w (Python < 3.11) or toml library

See Also

See also

arillso.system.from_toml filter plugin

Convert TOML string to Python object

arillso.system.to_nice_toml filter plugin

Convert variable to nicely formatted TOML string

Examples

# Convert dictionary to TOML string
- name: Generate TOML configuration
  ansible.builtin.set_fact:
    toml_output: "{{ config_dict | arillso.system.to_toml }}"

# Example with inline dictionary
- name: Convert inline dict to TOML
  ansible.builtin.debug:
    msg: "{{ {'title': 'Example', 'owner': {'name': 'Admin'}} | arillso.system.to_toml }}"

# Use in template to create TOML config file
- name: Create TOML config file
  ansible.builtin.template:
    src: config.toml.j2
    dest: /etc/app/config.toml
  vars:
    toml_content: "{{ application_config | arillso.system.to_toml }}"

Return Value

Key

Description

Return value

string

The TOML serialized string representing the input dictionary.

Returned: success

Authors

  • arillso