With open source software it is common to download and install software from the web. And with distributed computing plaftforms like hadoop software need to get installed on multiple servers. This can be automated using Chef. The following is an example of how zookeeper software can be downloaded and installed.
- Create a Chef cookbook. Assumed that Chef is already available for use.
- Create default.rb under attributes folder with attributes for where the software need to be installed, version of software to be downloaded and the URL to download from
1 2 3
- Create a default recipe “default.rb” under the recipe folder in the cookbook with the following resources
1 2 3 4 5 6 7 8
The tarball variable will store the name of the zookeeper gzip file available for download from the apache mirror site The download_file variable stores the complete URL including the gzip file name for download. Both these variables use values from the attribute values defined in attributes file. “remote_file” resource is the chef resource which is used to retrieve remote files. The name passed to the remote_file resource is the destination where the remote file need to be stored and in this case is the temporary cache directory used by Chef. The download is defined to happen only if the tar file is not already available in the cache thus preventing unnecessary download.
1 2 3 4 5 6 7 8 9 10
“zk_install_dir” variable will store the directory into which the zookeeper software need to be installed into and uses the value set to default[:zookeeper][:install] attribute in the attribute file. The execute resource executes the tar command to untar/unzip the gzip file downloaded from the apache site into the folder store in the “zk_install_dir” variable. The tar command gets executed only if a “zookeeper” directory is not in the “/opt” directory which is the value set in “zk_install_dir”.
- Once untarred the directory created will include the version number of zookeeper downloaded. Inorder to remove the version number the following execute resource can be used.
1 2 3 4 5 6 7 8
This recipe downloaded and installed software at the required location. Using Chef we can run the recipe in multiple nodes and automate the repeatable process. We will improve on this recipe next time.
Until next time Happy computing!!