Excellent find Vladimir! I just shared this with my team. I was unaware of 'jc'.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Feb 28, 2023, at 2:11 AM, Vladimir Botka <[email protected]> wrote:

On Mon, 27 Feb 2023 21:07:45 -0800 (PST)
Veera <[email protected]> wrote:

load_avg: "{{ up_out.stdout_lines[0].split()[7:] }}"

Given the registered variable *up_out*

 - command: uptime
   register: up_out

Use the filter community.general.jc to parse the stdout. The utility
*jc* "converts the output of many commands, file-types, and strings
to JSON or YAML". For example,

 uptime: "{{ up_out.stdout|community.general.jc('uptime') }}"

gives

 uptime:
   load_15m: 1.21
   load_1m: 1.84
   load_5m: 1.41
   time: 07:57:41
   time_hour: 7
   time_minute: 57
   time_second: 41
   uptime: 11 days, 18:12
   uptime_days: 11
   uptime_hours: 18
   uptime_minutes: 12
   uptime_total_seconds: 1015920
   users: 2

The first three attributes come from "load average". Quoting from man
uptime: "The averages are taken over the three time intervals." Now,
the usage is trivial. For example,

 load_average: >
   {{ uptime.load_1m }},
   {{ uptime.load_5m}},
   {{ uptime.load_15m }}

gives

 load_average: |-
   1.84, 1.41, 1.21

--
Vladimir Botka

--
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20230228081123.140af349%40gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/D209028D-24B1-4996-86A2-83EA001FBDB3%40nist.gov.

Reply via email to