From 14805033261c6128a0346be4c59e99630acc9ad2 Mon Sep 17 00:00:00 2001 From: fbourqui Date: Mon, 14 Feb 2022 22:01:27 +0100 Subject: [PATCH] Update complex_data_manipulation example uptime in days/h/m/s (#77019) --- docs/docsite/rst/user_guide/complex_data_manipulation.rst | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/docsite/rst/user_guide/complex_data_manipulation.rst b/docs/docsite/rst/user_guide/complex_data_manipulation.rst index acd5159da0d..d0a6616ccca 100644 --- a/docs/docsite/rst/user_guide/complex_data_manipulation.rst +++ b/docs/docsite/rst/user_guide/complex_data_manipulation.rst @@ -293,15 +293,13 @@ An example on how to use facts to find a host's data that meets condition X: vars: uptime_of_host_most_recently_rebooted: "{{ansible_play_hosts_all | map('extract', hostvars, 'ansible_uptime_seconds') | sort | first}}" - -Using an example from @zoradache on reddit, to show the 'uptime in days/hours/minutes' (assumes facts where gathered). -https://www.reddit.com/r/ansible/comments/gj5a93/trying_to_get_uptime_from_seconds/fqj2qr3/ +An example to show a host uptime in days/hours/minutes/seconds (assumes facts where gathered). .. code-block:: YAML+Jinja - - name: Show the uptime in a certain format + - name: Show the uptime in days/hours/minutes/seconds ansible.builtin.debug: - msg: Timedelta {{ now() - now().fromtimestamp(now(fmt='%s') | int - ansible_uptime_seconds) }} + msg: Uptime {{ now().replace(microsecond=0) - now().fromtimestamp(now(fmt='%s') | int - ansible_uptime_seconds) }} .. seealso::