Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the disk available in a Chef recipe?

Tags:

chef-infra

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?

like image 408
Jordan Dea-Mattson Avatar asked Jan 11 '13 21:01

Jordan Dea-Mattson


1 Answers

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\""
    ]
  }
}
like image 171
Jordan Dea-Mattson Avatar answered Sep 28 '22 10:09

Jordan Dea-Mattson