Skip to content

Instantly share code, notes, and snippets.

@fujin
Created February 4, 2009 13:50
Show Gist options
  • Save fujin/58107 to your computer and use it in GitHub Desktop.
Save fujin/58107 to your computer and use it in GitHub Desktop.
define :add_htpasswd_users do
params[:users].each do |auth|
execute "add_htpasswd_#{auth[:username]}" do
command "echo '#{auth[:username]}:#{auth[:password]}' >> #{params[:name]}"
not_if do
if File.exists?(params[:name])
File.open(params[:name]) do |password_file|
password_file.detect { |line| line =~ /#{auth[:username]}:#{auth[:password]}/ }
end
end
end
end
end
end
# attributes
nagios Mash.new
nagios[:users] = Array.new
nagios[:users] << {:username => "admin", :password => "whatever"}
Chef::Log.debug("node = #{node}")
Chef::Log.debug("node[:nagios] = #{node[:nagios].inspect}")
Chef::Log.debug("node[:nagios][:users] = #{node[:nagios][:users].class}, #{node[:nagios][:users].inspect}")
# works
blah = node[:nagios][:users]
add_htpasswd_users "/tmp/out" do
users(blah)
end
# broken
# /var/chef/cache/cookbooks/testing/recipes/default.rb:32:in `[]': Symbol as array index (TypeError)
add_htpasswd_users "/tmp/out" o
users(node[:nagios][:users])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment