Skip to content

Instantly share code, notes, and snippets.

@lusis
Created March 11, 2011 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lusis/866206 to your computer and use it in GitHub Desktop.
Save lusis/866206 to your computer and use it in GitHub Desktop.
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[:platform]
when "redhat", "centos"
if node[:platform_version].to_f >= 5
%w[ CentOS-Base epel elff ].each do |repo_file|
cookbook_file "/etc/yum.repos.d/#{repo_file}.repo" do
mode 0644
source "#{repo_file}.repo"
action :create
end
end
%w[ CentOS-Media kbs-el5-ruby187 cloudkick epel-testing elff-testing jpackage50 s3tools ].each do |banned_repo|
file "/etc/yum.repos.d/#{banned_repo}.repo" do
action :delete
end
end
directory "/mnt/yumrepo" do
mode 0755
owner "root"
group "root"
action :create
recursive true
end
template "/root/.yums3cfg" do
mode 0640
owner "root"
group "root"
action :create
source "yums3cfg.erb"
variables({ :access_key => s3_access_key, :secret_key => s3_secret_key })
end
cron "sync_repo" do
hour "4"
minute "0"
command "s3cmd -c /root/.yums3cfg sync s3://rpms/ /mnt/yumrepo/ --recursive --exclude=$folder$ --delete-removed"
only_if do File.exist?("/root/.yums3cfg") end
end
package "s3cmd" do
version "0.9.9.91"
action :upgrade
provider Chef::Provider::Package::Yum
notifies :run, "execute[initial_repo_sync]", :immediately
end
execute "initial_repo_sync" do
command "s3cmd -c /root/.yums3cfg sync s3://rpms/ /mnt/yumrepo/ --recursive --exclude=$folder$ --delete-removed"
action :nothing
not_if do File.exist?("/mnt/yumrepo/i386/repodata") end
end
# delay this till the end so that yum doesn't bork
%w[ company ].each do |repo_file|
cookbook_file "/etc/yum.repos.d/#{repo_file}.repo" do
mode 0644
source "#{repo_file}.repo"
action :create
end
end
end
else
Chef::Log.info("I don't support #{node.platform} yet")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment