I would like to create a playbook that extract the used
space for /boot
through the shell command df -B MB
.
For this example, the playbook will show 358MB
for the controller node.
I would like to know how to filter the server_info.stdout_lines
in order to get the desired result.
I believe that we can do it with the regex_search
filter.
- hosts: all
gather_facts: True
become: True
tasks:
- name: show used space on /boot
shell: "df -B MB"
register: server_info
- debug:
msg: "{{ server_info.stdout_lines }}"
TASK [debug] *****************************************************************************************************************
ok: [control] => {
"msg": [
"Filesystem 1MB-blocks Used Available Use% Mounted on",
"devtmpfs 1458MB 0MB 1458MB 0% /dev",
"tmpfs 1488MB 1MB 1488MB 1% /dev/shm",
"tmpfs 1488MB 10MB 1478MB 1% /run",
"tmpfs 1488MB 0MB 1488MB 0% /sys/fs/cgroup",
"/dev/mapper/cs-root 19267MB 6268MB 13000MB 33% /",
"/dev/sda1 1064MB 358MB 706MB 34% /boot",
"tmpfs 298MB 1MB 298MB 1% /run/user/42",
"tmpfs 298MB 1MB 298MB 1% /run/user/1000"
]
}
ok: [ansible2] => {
"msg": [
"Filesystem 1MB-blocks Used Available Use% Mounted on",
"devtmpfs 1458MB 0MB 1458MB 0% /dev",
"tmpfs 1488MB 0MB 1488MB 0% /dev/shm",
"tmpfs 1488MB 10MB 1478MB 1% /run",
"tmpfs 1488MB 0MB 1488MB 0% /sys/fs/cgroup",
"/dev/mapper/cs-root 19267MB 6264MB 13003MB 33% /",
"/dev/sda1 1064MB 360MB 704MB 34% /boot",
"tmpfs 298MB 1MB 298MB 1% /run/user/42",
"tmpfs 298MB 1MB 298MB 1% /run/user/1000"
]
}