Skip to content

Commit

Permalink
remove slice docs (ansible#37946)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoca authored and Alexander Bethke committed May 15, 2018
1 parent 01a84d1 commit 91b9efe
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions docs/docsite/rst/user_guide/playbooks_filters.rst
Expand Up @@ -955,26 +955,15 @@ To make use of one attribute from each item in a list of complex variables, use
# get a comma-separated list of the mount points (e.g. "/,/mnt/stuff") on a host
{{ ansible_mounts|map(attribute='mount')|join(',') }}

.. versionadded:: 2.5

The `slice` filter can be used to extract the values of specific keys from a
hash::

{{ {'x': 1, 'y': 2, 'z': 3 } | slice(['x', 'z']) }}

This will result in::

[1, 2]

To get date object from string use the `to_datetime` filter, (new in version in 2.2)::

# Get total amount of seconds between two dates. Default date format is %Y-%m-%d %H:%M:%S but you can pass your own format
{{ (("2016-08-14 20:00:12"|to_datetime) - ("2015-12-25"|to_datetime('%Y-%m-%d'))).total_seconds() }}

# Get remaining seconds after delta has been calculated. NOTE: This does NOT convert years, days, hours, etc to seconds. For that, use total_seconds()
{{ (("2016-08-14 20:00:12"|to_datetime) - ("2016-08-14 18:00:00"|to_datetime)).seconds }}
# This expression evaluates to "12" and not "132". Delta is 2 hours, 12 seconds

# get amount of days between two dates. This returns only number of days and discards remaining hours, minutes, and seconds
{{ (("2016-08-14 20:00:12"|to_datetime) - ("2015-12-25"|to_datetime('%Y-%m-%d'))).days }}

Expand Down

0 comments on commit 91b9efe

Please sign in to comment.