Note
This filter plugin is part of the community.general collection (version 10.7.3).
You might already have this collection installed if you are using the ansible package. 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 community.general. You need further requirements to be able to use this filter plugin, see Requirements for details.
To use it in a playbook, specify: community.general.to_prettytable.
New in community.general 10.7.0
The below requirements are needed on the local controller node that executes this filter.
This describes the input of the filter, the value before | community.general.to_prettytable.
Parameter | Comments |
|---|---|
Input list / elements=dictionary / required | A list of dictionaries to format. |
This describes keyword parameters of the filter. These are the values key1=value1, key2=value2 and so on in the following example: input | community.general.to_prettytable(key1=value1, key2=value2, ...)
Parameter | Comments |
|---|---|
column_alignments dictionary | Dictionary where keys are column names and values are alignment settings. Valid alignment values are For example, |
column_order list / elements=string | List of column names to specify the order of columns in the table. |
header_names list / elements=string | List of custom header names to use instead of dictionary keys. |
---
- name: Set a list of users
ansible.builtin.set_fact:
users:
- name: Alice
age: 25
role: admin
- name: Bob
age: 30
role: user
- name: Display a list of users as a table
ansible.builtin.debug:
msg: >-
{{
users | community.general.to_prettytable
}}
- name: Display a table with custom column ordering
ansible.builtin.debug:
msg: >-
{{
users | community.general.to_prettytable(
column_order=['role', 'name', 'age']
)
}}
- name: Display a table with selective column output (only show name and role fields)
ansible.builtin.debug:
msg: >-
{{
users | community.general.to_prettytable(
column_order=['name', 'role']
)
}}
- name: Display a table with custom headers
ansible.builtin.debug:
msg: >-
{{
users | community.general.to_prettytable(
header_names=['User Name', 'User Age', 'User Role']
)
}}
- name: Display a table with custom alignments
ansible.builtin.debug:
msg: >-
{{
users | community.general.to_prettytable(
column_alignments={'name': 'center', 'age': 'right', 'role': 'left'}
)
}}
- name: Combine multiple options
ansible.builtin.debug:
msg: >-
{{
users | community.general.to_prettytable(
column_order=['role', 'name', 'age'],
header_names=['Position', 'Full Name', 'Years'],
column_alignments={'name': 'center', 'age': 'right', 'role': 'left'}
)
}}
Key | Description |
|---|---|
Return value string | The formatted ASCII table. Returned: success |
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/general/to_prettytable_filter.html