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.
To use it in a playbook, specify: community.general.to_time_unit.
New in community.general 0.2.0
This describes the input of the filter, the value before | community.general.to_time_unit.
Parameter | Comments |
|---|---|
Input string / required | The time string to convert. Can use the units Valid strings are space separated combinations of an integer with an optional minus sign and a unit. Examples are |
This describes positional parameters of the filter. These are the values positional1, positional2 and so on in the following example: input | community.general.to_time_unit(positional1, positional2, ...)
Parameter | Comments |
|---|---|
unit string | Time unit to convert the duration to. Choices:
|
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_time_unit(key1=value1, key2=value2, ...)
Parameter | Comments |
|---|---|
month float | Number of days per month. Default: |
year float | Number of days per year. Default: |
Note
input | community.general.to_time_unit(positional1, positional2, key1=value1, key2=value2)
- name: Convert a duration into seconds
ansible.builtin.debug:
msg: "{{ '1053d 17h 53m -10s 391ms' | community.general.to_time_unit('s') }}"
Key | Description |
|---|---|
Return value float | Number of time units. 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_time_unit_filter.html