I would like to extract some words from an Ansible output. For example, I would like to extract from sudo monit status
command the bolded words(** **) and store them in 2 variables(let's say variable 'A' for OK and variable 'B' for the uptime period) which will be used later on into a Jinja2 template:
[ansible@server ~]$ sudo monit status
Monit 5.25.1 uptime: 3m
System 'server'
status **OK**
monitoring status Monitored
monitoring mode active
on reboot start
load average [0.03] [0.07] [0.11]
cpu 0.1%us 0.2%sy 0.0%wa
memory usage 338.1 MB [18.4%]
swap usage 0 B [0.0%]
uptime **29m**
boot time Fri, 30 Mar 2018 11:56:12
data collected Fri, 30 Mar 2018 12:25:24
To accomplish this, I have started an Ansible playbook, but in this way, I'm taking all information from the output:
--- #Health check
- hosts: appserver
connection: ssh
sudo: yes
user: ansible
tasks:
- name: Monitor the status
shell: "{{item}}"
with_items:
- monit status
register: monitinfo
tags: basic_monitoring
- debug: var=monitinfo
Any idea how this can be accomplished?
Thank you,
Romain