Add a new filter: strftime. Use the well known function to format a date output. (#23832)

(cherry picked from commit 3f5b304fc28b6c34df9ea6a4c3531dc422ce198b)
rebased for @yannig
This commit is contained in:
Brian Coca
2017-04-21 14:48:45 -04:00
committed by scottb
parent 8517fbf936
commit 3358abcf49
2 changed files with 33 additions and 1 deletions

View File

@@ -644,6 +644,24 @@ To always exhaust all list use ``zip_longest``::
debug: msg="{{ [1,2,3]|zip_longest(['a','b','c','d','e','f'], [21, 22, 23], fillvalue='X')|list }}"
.. versionadded:: 2.4
To format a date using a string (like with the shell date command), use the "strftime" filter::
# Display year-month-day
{{ '%Y-%m-%d' | strftime }}
# Display hour:min:sec
{{ '%H:%M:%S' | strftime }}
# Use ansible_date_time.epoch fact
{{ '%Y-%m-%d %H:%M:%S' | strftime(ansible_date_time.epoch) }}
# Use arbitrary epoch value
{{ '%Y-%m-%d' | strftime(0) }} # => 1970-01-01
{{ '%Y-%m-%d' | strftime(1441357287) }} # => 2015-09-04
.. note:: To get all string possibilities, check https://docs.python.org/2/library/time.html#time.strftime
Debugging Filters
`````````````````