ansible.builtin.strftime filter – date formating
Note
This filter plugin is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
plugin name
strftime
even without specifying the collections:
keyword.
However, we recommend you use the FQCN for easy linking to the
plugin documentation and to avoid conflicting with other collections that may have
the same filter plugin name.
New in Ansible 2.4
Synopsis
Using Python’s
strftime
function, take a data formating string and a date/time to create a formated date.
Input
This describes the input of the filter, the value before | ansible.builtin.strftime
.
Parameter |
Comments |
---|---|
A formating string following See the Python documentation for a reference. |
Positional parameters
This describes positional parameters of the filter. These are the values positional1
, positional2
and so on in the following example: input | ansible.builtin.strftime(positional1, positional2, ...)
.
Parameter |
Comments |
---|---|
Datetime in seconds from |
|
Whether time supplied is in UTC. Choices:
|
Notes
Note
This is a passthrough to Python’s
stftime
.
Examples
# Display year-month-day
{{ '%Y-%m-%d' | strftime }}
# => "2021-03-19"
# Display hour:min:sec
{{ '%H:%M:%S' | strftime }}
# => "21:51:04"
# Use ansible_date_time.epoch fact
{{ '%Y-%m-%d %H:%M:%S' | strftime(ansible_date_time.epoch) }}
# => "2021-03-19 21:54:09"
# Use arbitrary epoch value
{{ '%Y-%m-%d' | strftime(0) }} # => 1970-01-01
{{ '%Y-%m-%d' | strftime(1441357287) }} # => 2015-09-04
Return Value
Key |
Description |
---|---|
A formatted date/time string. Returned: success |
Hint
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.