|
|
|
@ -461,6 +461,25 @@ To escape special characters within a regex, use the "regex_escape" filter::
|
|
|
|
|
# convert '^f.*o(.*)$' to '\^f\.\*o\(\.\*\)\$'
|
|
|
|
|
{{ '^f.*o(.*)$' | regex_escape() }}
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 2.0
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
A few useful filters are typically added with each new Ansible release. The development documentation shows
|
|
|
|
|
how to extend Ansible filters by writing your own as plugins, though in general, we encourage new ones
|
|
|
|
|
to be added to core so everyone can make use of them.
|
|
|
|
|