Add PostgreSQL primary support to the kosmos-ejabberd cookbook

* Move the PostgreSQL user and database creation to a pg_db recipe
* Generate access rights for the ejabberd servers in the pg_db recipe
* Connect to the PostgreSQL primary instead of localhost

Refs #180
This commit is contained in:
Greg Karékinian
2020-06-10 18:38:40 +02:00
parent 091a46e972
commit 2c21d6255b
3 changed files with 83 additions and 23 deletions

View File

@@ -28,11 +28,6 @@ include_recipe "kosmos-postgresql"
ejabberd_credentials = data_bag_item("credentials", "ejabberd")
cookbook_file "#{Chef::Config[:file_cache_path]}/pg.sql" do
source "pg.sql"
mode "0664"
end
ejabberd_version = node["kosmos-ejabberd"]["version"]
package_checksum = node["kosmos-ejabberd"]["checksum"]
package_path = "#{Chef::Config['file_cache_path']}/ejabberd_#{ejabberd_version}-0_amd64.deb"
@@ -52,11 +47,6 @@ end
postgresql_data_bag_item = data_bag_item('credentials', 'postgresql')
postgresql_user 'ejabberd' do
action :create
password postgresql_data_bag_item['ejabberd_user_password']
end
hosts = [
{
name: "kosmos.org",
@@ -111,21 +101,14 @@ ldap_base = "cn=users,dc=kosmos,dc=org"
admin_users = ejabberd_credentials['admins']
postgresql_primary_node = postgresql_primary
postgresql_server = postgresql_primary_node[:ipaddress]
# PostgreSQL is on the same server, connect through localhost
postgresql_server = "localhost" if postgresql_primary_node[:hostname] == node[:hostname]
hosts.each do |host|
ldap_rootdn = "uid=xmpp,ou=#{host[:name]},cn=applications,dc=kosmos,dc=org"
postgresql_database host[:sql_database] do
owner 'ejabberd'
action :create
notifies :run, "execute[create db schema #{host[:sql_database]}]", :delayed
end
execute "create db schema #{host[:sql_database]}" do
user "ejabberd"
command "psql #{host[:sql_database]} < #{Chef::Config[:file_cache_path]}/pg.sql"
action :nothing
end
template "/opt/ejabberd/conf/#{host[:name]}.yml" do
source "vhost.yml.erb"
mode 0640
@@ -133,6 +116,7 @@ hosts.each do |host|
group 'ejabberd'
sensitive true
variables pgsql_password: postgresql_data_bag_item['ejabberd_user_password'],
sql_server: postgresql_server,
host: host,
ldap_base: ldap_base,
ldap_server: ldap_domain,