While a Chef recipe is executing, I want to determine if there is sufficient free disk space available to perform an operation.
How best to do this?
Ohai detects certain properties of a a node each time it is run. These properties are captured as automatic attributes and are available to you as node attributes.
The attribute node['filesystem'] contains information about each of the devices on your system. To get the space available in kb, for a specific device:
node['filesystem']['/dev/xvda1']['kb_available']
The following is an example of the filesystem attribute JSON from Ohai:
"filesystem": {
"/dev/xvda1": {
"kb_size": "521882300",
"kb_used": "119914572",
"kb_available": "375474240",
"percent_used": "25%",
"mount": "/",
"fs_type": "ext4",
"mount_options": [
"rw"
],
"uuid": "248b8180-f75f-48fc-a8be-e3ff3506c4d6"
},
"tmpfs": {
"kb_size": "1987292",
"kb_used": "0",
"kb_available": "1987292",
"percent_used": "0%",
"mount": "/dev/shm",
"fs_type": "tmpfs",
"mount_options": [
"rw",
"rootcontext=\"system_u:object_r:tmpfs_t:s0\""
]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With