From 0301c507208ff895645e23b1d766438af795ebbc Mon Sep 17 00:00:00 2001 From: Luke Hoersten Date: Sun, 14 Jun 2020 15:22:14 -0500 Subject: Added postgresql for prosody. --- prosody/defaults/main.yaml | 5 +++++ prosody/tasks/main.yaml | 21 ++++++++++++++++++++- prosody/templates/prosody.cfg.lua.j2 | 19 +++++++++++++++---- prosody/templates/setup_db.psql.j2 | 2 ++ 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 prosody/templates/setup_db.psql.j2 (limited to 'prosody') diff --git a/prosody/defaults/main.yaml b/prosody/defaults/main.yaml index ed97d53..440d5c2 100644 --- a/prosody/defaults/main.yaml +++ b/prosody/defaults/main.yaml @@ -1 +1,6 @@ --- + +prosody_ssl_dir: "/etc/prosody/certs/{{prosody_vhost}}" + +prosody_db: "prosody_{{prosody_instance}}" +prosody_db_port: "5432" diff --git a/prosody/tasks/main.yaml b/prosody/tasks/main.yaml index d4177a9..e58cd0b 100644 --- a/prosody/tasks/main.yaml +++ b/prosody/tasks/main.yaml @@ -2,8 +2,11 @@ - name: install prosody become: yes - apt: name="prosody" + apt: name="{{item}}" notify: restart prosody + loop: + - "prosody" + - "lua-dbi-postgresql" - name: configure prosody become: yes @@ -31,6 +34,22 @@ - "{{prosody_ssl_privkey_src}}" - "{{prosody_ssl_cert_src}}" +- name: install db schema file + become: yes + template: + src: "setup_db.psql.j2" + dest: "/tmp/setup_db_{{prosody_db}}.psql" + owner: "postgres" + group: "postgres" + mode: "0600" + changed_when: false + +- name: install psql + become: yes + become_user: "postgres" + command: "psql -f /tmp/setup_db_{{prosody_db}}.psql" + changed_when: false + - name: enable prosody site become: yes file: diff --git a/prosody/templates/prosody.cfg.lua.j2 b/prosody/templates/prosody.cfg.lua.j2 index 15a1b38..32bc1a6 100644 --- a/prosody/templates/prosody.cfg.lua.j2 +++ b/prosody/templates/prosody.cfg.lua.j2 @@ -1,8 +1,19 @@ VirtualHost "{{prosody_vhost}}" - ssl = { - key = "{{prosody_ssl_privkey}}"; - certificate = "{{prosody_ssl_cert}}"; - } + +ssl = { + key = "{{prosody_ssl_privkey}}"; + certificate = "{{prosody_ssl_cert}}"; +} + +storage = "sql" +sql = { + driver = "PostgreSQL"; + database = "{{prosody_db}}"; + host = "localhost"; + port = {{prosody_db_port}}; + username = "{{prosody_db}}"; + password = "{{prosody_db_pass}}"; +} ------ Components ------ -- You can specify components to add hosts that provide special services, diff --git a/prosody/templates/setup_db.psql.j2 b/prosody/templates/setup_db.psql.j2 new file mode 100644 index 0000000..25e9ec0 --- /dev/null +++ b/prosody/templates/setup_db.psql.j2 @@ -0,0 +1,2 @@ +CREATE USER {{prosody_db}} WITH ENCRYPTED PASSWORD '{{prosody_db_pass}}'; +CREATE DATABASE {{prosody_db}} ENCODING 'UTF8' LC_COLLATE='C.UTF-8' LC_CTYPE='C.UTF-8' template=template0 OWNER {{prosody_db}}; -- cgit v1.2.3