-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_role.rb
37 lines (32 loc) · 1.01 KB
/
create_role.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# ##################################################
# node
# ##################################################
ROLE = node[:postgresql][:create_role]
# MEMO: CREATE ROLEなどの実行を行うためサービス起動する
service 'postgresql-9.6.service' do
action :start
end
# ##################################################
# DROP ROLE
# ##################################################
ROLE.each do |role|
drop_command = %(psql --command="DROP ROLE IF EXISTS #{role[:name]}")
execute drop_command do
user 'postgres'
end
end
# ##################################################
# CREATE ROLE
# ##################################################
ROLE.each do |role|
name = role[:name]
option = role[:option]
password = role[:password]
sql = %W[CREATE ROLE #{name}]
sql.concat(%w[WITH]).concat(option) unless option.nil?
sql.concat(%w[PASSWORD]) << "'#{password}'" if password
create_command = %(psql --command="#{sql.join("\s")}")
execute create_command do
user 'postgres'
end
end