Created
February 4, 2009 13:50
-
-
Save fujin/58107 to your computer and use it in GitHub Desktop.
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
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 |
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
# attributes | |
nagios Mash.new | |
nagios[:users] = Array.new | |
nagios[:users] << {:username => "admin", :password => "whatever"} |
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
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