Last active
December 15, 2015 18:59
-
-
Save liangzan/5308177 to your computer and use it in GitHub Desktop.
pg_users_chef_recipe.rb
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
include_recipe "postgresql::server" | |
node[:notifymode][:db_users].each do |user| | |
execute "create-database-user" do | |
exists = <<-EOH | |
sudo -u postgres psql -U postgres -c "select * from pg_user where usename='#{user[:name]}'" | grep -c #{user[:name]} | |
EOH | |
command "echo \"CREATE ROLE #{user[:name]} with CREATEDB LOGIN PASSWORD '#{user[:password]}'\" | sudo -u postgres psql -U postgres" | |
not_if exists | |
end | |
end | |
node[:notifymode][:dbs].each do |db| | |
execute "create-database" do | |
exists = <<-EOH | |
sudo -u postgres psql -U postgres -c "select * from pg_database WHERE datname='#{db[:name]}'" | grep -c #{db[:name]} | |
EOH | |
command "sudo -u postgres createdb -U postgres -O #{db[:owner]} -E utf8 #{db[:name]}" | |
not_if exists | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment