Skip to content

Instantly share code, notes, and snippets.

@adamhjk
Created February 20, 2010 02:08
Show Gist options
  • Save adamhjk/309444 to your computer and use it in GitHub Desktop.
Save adamhjk/309444 to your computer and use it in GitHub Desktop.
# rsync/definition/rsync_target.rb
define :rsync_target, :path => nil, :comment => nil, :action => :set do
t = begin
resources(:template => "/etc/rsyncd.conf")
rescue
template "/etc/rsyncd.conf" do
owner "root"
group "root"
source "rsyncd.conf.erb"
cookbook "rsyncd"
variables { :targets => {} }
end
end
target_opts = params.clone
target_opts.delete(:name)
case params[:action]
when :set
t.variables[:targets].merge({ params[:name] => target_opts})
when :unset
t.variables[:targets].delete(params[:name])
end
end
# rsync/templates/rsyncd.conf.erb
<%- @targets.sort.each do |target| %>
[<%= target[0] %>]
<%- target[1].each do |attr, value| %>
<%= attr %> = <%= value %>
<%- end %>
<%- end %>
# some recipe
rsync_target "snoopy" do
path "/tmp/snoopy"
comment "I like to snoop"
uid "francis"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment