«

»

Sep 21

Chef calculate checksum

I’ve been working with Chef at work and there are several items that I keep looking up.  The first of these is calculating the checksum for a file that chef downloads.  Since we are doing some customized recipes I keep looking at having to grab a file and check the checksum, although not completely necessary it is a nice to have.  For example formatting the EBS volumes I use something that looks like this:

remote_file "#{Chef::Config[:file_cache_path]}/format9-11-13.sh" do
source "http://somebucket.s3.amazonaws.com/format.sh"
checksum "70b8c25a25fb0aeca95b89d33571b6021a334ebbb706444fd266a6d73104f62c"
end

For Chef you need to use the following:

shasum -a 256 /path/to/file

That will generate the checksum you need in your cookbook. You don’t need to use the whole thing either, just a portion is needed as shown here: https://coderwall.com/p/bbfjrw

 

To calculate a checksum normally use the SHA-256 algorithm. Most of the time you would use the built-in cksum command like so:

$ cksum sample
2072207789 477 sample

Where the CRC (Cyclical Redundancy Check) or checksum is the first number then the size then the name of the file.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Close Bitnami banner
Bitnami