Update complex_data_manipulation example uptime in days/h/m/s (#77019)

pull/77023/head
fbourqui 2 years ago committed by GitHub
parent f82b1ba67c
commit 1480503326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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::

Loading…
Cancel
Save