mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-17 10:25:27 -07:00
Add 'type' filter for display the underlying python type of a variable (#18242)
* Add 'type' filter for display the underlying python type of a variable * Update playbooks_filters.rst Minor copyedit.
This commit is contained in:
parent
71819c0a60
commit
cb1e3dab0d
2 changed files with 15 additions and 0 deletions
|
@ -514,6 +514,18 @@ To get date object from string use the `to_datetime` filter, (new in version in
|
||||||
# get amount of seconds between two dates, default date format is %Y-%d-%m %H:%M:%S but you can pass your own one
|
# get amount of seconds between two dates, default date format is %Y-%d-%m %H:%M:%S but you can pass your own one
|
||||||
{{ (("2016-08-04 20:00:12"|to_datetime) - ("2015-10-06"|to_datetime('%Y-%d-%m'))).seconds }}
|
{{ (("2016-08-04 20:00:12"|to_datetime) - ("2015-10-06"|to_datetime('%Y-%d-%m'))).seconds }}
|
||||||
|
|
||||||
|
Debugging Filters
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
.. versionadded:: 2.3
|
||||||
|
|
||||||
|
Use the ``type`` filter to display the underlying Python type of a variable.
|
||||||
|
This can be useful in debugging in situations where you may need to know the exact
|
||||||
|
type of a variable::
|
||||||
|
|
||||||
|
{{ myvar | type }}
|
||||||
|
|
||||||
|
|
||||||
A few useful filters are typically added with each new Ansible release. The development documentation shows
|
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
|
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.
|
to be added to core so everyone can make use of them.
|
||||||
|
|
|
@ -525,4 +525,7 @@ class FilterModule(object):
|
||||||
# skip testing
|
# skip testing
|
||||||
'skipped' : skipped,
|
'skipped' : skipped,
|
||||||
'skip' : skipped,
|
'skip' : skipped,
|
||||||
|
|
||||||
|
# debug
|
||||||
|
'type': lambda o: o.__class__.__name__,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue