I am trying to input a list of hosts, then the code will check which systems have space more than 1 GB in /, and less than 1GB and display the output. The output I am getting is host wise like this:- Current Output:-
ok: [hostname1.com] => {
"msg": "hostname1.com : Space is more than 1GB"
}
ok: [hostname2.com] => {
"msg": "hostname2.com : Space is less than 1GB"
}
ok: [hostname3.com] => {
"msg": "hostname3.com : Space is more than 1GB"
I want to group the output as, systems whose space is more are grouped and displayed other than systems whose space is less , example:- (Needed Output)
ok: [hosts] => {
"msg": "hostname1.com : Space is more than 1GB"
"hostname2.com : Space is more than 1GB"
}
ok: [hosts] => {
"msg": "hostname3.com : Space is less than 1GB"
"hostname4.com : Space is less than 1GB"
My code:
- name: Check the space in /
shell: df -h / | grep [0-9]% | awk '{ print 0+$4 }'
register: space
- debug:
msg: "{{ inventory_hostname }} : Space is more than 1GB"
when: (space.stdout| int) > 1
- debug:
msg: "{{ inventory_hostname }} : Space is less than 1GB"
when: (space.stdout| int) < 1