Created
January 24, 2012 21:29
-
-
Save mostlygeek/1672827 to your computer and use it in GitHub Desktop.
Chef ruby_block and dynamic resource creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby_block "sync_build_from_s3" do | |
action :nothing | |
block do | |
# latest_file contains path to the latest.txt, which lists files to sync | |
file = File.new(latest_file, "r"); | |
run_context = Chef::RunContext.new(node, {}) | |
# | |
# Create the directory to hold the new build files | |
# | |
tmpDir = "/opt/builds/#{File.dirname(file.first)}" # get the build path | |
dir = Chef::Resource::Directory.new(tmpDir, run_context) | |
dir.recursive(true) | |
dir.run_action(:create) | |
# | |
# Download the build files listed in the downloaded manifest file | |
# | |
file.rewind | |
while (line = file.gets) do | |
# | |
# Define the S3 remote file resources based on data in manifest file | |
# -- this is the only way (I found) to inject new resources dynamically at runtime | |
# | |
local_file = "/opt/builds/#{line}" | |
f = Chef::Resource::S3AwareRemoteFile.new(local_file, run_context) | |
f.access_key_id aws_access_key | |
f.secret_access_key aws_secret_key | |
f.source "s3://my_bucket/#{line}" | |
f.owner "root" | |
f.group "root" | |
f.mode 0644 | |
f.run_action :create_if_missing | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment