Skip to content

Instantly share code, notes, and snippets.

@lusis
Created January 4, 2011 21:22
Show Gist options
  • Save lusis/765444 to your computer and use it in GitHub Desktop.
Save lusis/765444 to your computer and use it in GitHub Desktop.
A sample recipe to install my erlang tarballs with the maximum amount of idempotence

Notes

While I call s3_file and use my databag_decrypt helpers, you can point to the downloads in my github repo here: https://github.com/lusis/erlang-and-centos/

The sha256 is in the filename so the checksum operator should work.

This is about as idempotent as I can get the cookbook. I've tested multiple scenarios:

  • missing symlink
  • missing installed product
  • from scratch with neither symlink or installed product
  • missing bin files

It uses erl +V to determine if the actual installed product is the one from the tarball.

default[:va_erlang][:version] = "R13B04"
# Output of erl +V
default[:va_erlang][:vm_ver] = "5.7.5"
default[:va_erlang][:i386][:checksum] = "8f2746a44a10395ba22998ca7ce4376d39f538b434bd7f3da6c2aaeacba7a5dc"
default[:va_erlang][:x86_64][:checksum] = "06aa746ebd26073de5e52fbe1c0b1ad759571f4f6f6540860d646d82ee7c6e5a"
default[:va_erlang][:do_profile] = true
default[:va_erlang][:do_symlink] = true
default[:va_erlang][:install_dir] = "/opt/erlang-#{node[:va_erlang][:version]}"
default[:va_erlang][:run_dir] = "/opt/erlang"
if [ -d "<%= node[:va_erlang][:run_dir] %>/bin" ];then
ERLANG_HOME=<%= node[:va_erlang][:run_dir] %>
PATH=$ERLANG_HOME/bin:$PATH
export ERLANG_HOME
export PATH
fi
include_recipe "s3client::default"
include_recipe "databag_decrypt::default"
s3_access_key = item_decrypt(search(:passwords, "id:s3_access_key").first[:data])
s3_secret_key = item_decrypt(search(:passwords, "id:s3_secret_key").first[:data])
case node.kernel.machine
when 'i686'
erl_arch = 'i386'
when 'x86_64'
erl_arch = 'x86_64'
else
Chef::Log.error("I don't understand your arch yet: #{node.kernel.machine}")
end
erl_checksum = node[:va_erlang][erl_arch.to_sym][:checksum]
# PITA to continually type out
erlang_file_name = "erlang-#{node[:va_erlang][:version]}-#{erl_arch}-bin-#{erl_checksum}.tar.gz"
erlang_tar_gz = File.join(Chef::Config[:file_cache_path], "/", erlang_file_name)
s3_file erlang_tar_gz do
bucket "our-packages"
object_name erlang_file_name
aws_access_key_id s3_access_key
aws_secret_access_key s3_secret_key
checksum erl_checksum
end
bash "install erlang #{node[:va_erlang][:version]}" do
cwd Chef::Config[:file_cache_path]
code <<-EOH
mkdir #{node[:va_erlang][:install_dir]}
tar -C #{node[:va_erlang][:install_dir]} -zxf #{erlang_tar_gz}
EOH
not_if "#{node[:va_erlang][:install_dir]}/erlang/bin/erl +V 2>&1 | awk '{ print $6 }' | grep '#{node[:va_erlang][:vm_ver]}' > /dev/null"
end
if node[:va_erlang][:do_symlink] == true and File.directory?("#{node[:va_erlang][:install_dir]}/erlang") then
link node[:va_erlang][:run_dir] do
to "#{node[:va_erlang][:install_dir]}/erlang"
end
end
if node[:va_erlang][:do_profile] == true then
template "/etc/profile.d/erlang.sh" do
source "erlang.sh.erb"
mode 0755
owner "root"
group "root"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment