Pleroma role updates. Added Postgresql role.
authorLuke Hoersten <luke@hoersten.org>
Sun, 17 Nov 2019 08:14:06 -0600
changeset 75 d8c87a41cc6d
parent 74 dc20ec78acdd
child 76 c10c50b3b471
Pleroma role updates. Added Postgresql role.
roles/nginx/tasks/main.yaml
roles/pleroma/defaults/main.yaml
roles/pleroma/meta/main.yaml
roles/pleroma/tasks/main.yaml
roles/pleroma/templates/prod.secret.exs.j2
roles/pleroma/templates/setup_db.psql.j2
roles/postgresql/defaults/main.yaml
roles/postgresql/handlers/main.yaml
roles/postgresql/tasks/main.yaml
--- a/roles/nginx/tasks/main.yaml	Sat Jan 19 13:45:58 2019 -0600
+++ b/roles/nginx/tasks/main.yaml	Sun Nov 17 08:14:06 2019 -0600
@@ -9,12 +9,6 @@
   template: src="{{nginx_conf_src}}" dest="/etc/nginx/sites-available/{{nginx_conf_dst}}"
   notify: restart nginx
 
-# https://certbot.eff.org/lets-encrypt/ubuntuxenial-nginx
-- name: add certbot (letsencrypt) repo
-  become: yes
-  apt_repository: repo="ppa:certbot/certbot"
-  when: nginx_enable_ssl
-
 - name: install nginx packages
   become: yes
   apt: name="python-certbot-nginx"
--- a/roles/pleroma/defaults/main.yaml	Sat Jan 19 13:45:58 2019 -0600
+++ b/roles/pleroma/defaults/main.yaml	Sun Nov 17 08:14:06 2019 -0600
@@ -20,9 +20,17 @@
 pleroma_db_host: "localhost"
 pleroma_db_superuser: "postgres"
 
+pleroma_version: "v1.0.6"
+
 pleroma_apt_packages:
-  - "postgresql"
-  - "esl-erlang"
   - "elixir"
+  - "git"
   - "build-essential"
-  - "git"
+
+  # - "erlang-dev"
+  # - "erlang-tools"
+  # - "erlang-parsetools"
+  # - "erlang-ssh"
+  # - "erlang-ssl"
+  # - "erlang-inets"
+  # - "erlang-xmerl"
--- a/roles/pleroma/meta/main.yaml	Sat Jan 19 13:45:58 2019 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
----
-
-dependencies:
-  - nginx
--- a/roles/pleroma/tasks/main.yaml	Sat Jan 19 13:45:58 2019 -0600
+++ b/roles/pleroma/tasks/main.yaml	Sun Nov 17 08:14:06 2019 -0600
@@ -2,11 +2,11 @@
 
 - name: add erland solutions key
   become: yes
-  apt_key: "url=http://packages.erlang-solutions.com/debian/erlang_solutions.asc"
+  apt_key: url="http://packages.erlang-solutions.com/debian/erlang_solutions.asc"
 
 - name: install erland solutions repo
   become: yes
-  apt_repository: repo="deb http://binaries.erlang-solutions.com/debian bionic contrib"
+  apt_repository: repo="deb http://binaries.erlang-solutions.com/debian buster contrib"
 
 - name: update apt package cache
   become: yes
@@ -26,6 +26,7 @@
   git:
     repo: "https://git.pleroma.social/pleroma/pleroma.git"
     dest: "~{{pleroma_user}}/pleroma"
+    version: "{{pleroma_version}}"
     force: yes
 
 - name: install pleroma config files
@@ -36,7 +37,6 @@
     group: "{{pleroma_user}}"
     mode: "0775"
   become: yes
-  become_user: "{{pleroma_user}}"
   with_items:
     - "setup_db.psql"
     - "prod.secret.exs"
@@ -45,11 +45,18 @@
 - name: install pleroma psql
   become: yes
   become_user: "{{pleroma_db_superuser}}"
-  command: "psql -f ~{{pleroma_user}}/pleroma/config/setup_db.psql -h {{pleroma_db_host}}"
+  command: "psql -f ~{{pleroma_user}}/pleroma/config/setup_db.psql"
   notify: restart pleroma
-  environment:
-    PGUSER: "{{pleroma_db_superuser}}"
-    PGPASSWORD: "{{pleroma_db_superpass}}"
+
+# - name: restore
+#   postgresql_db:
+#     state: "restore"
+#     db: "{{pleroma_user}}"
+#     target: "/tmp/{{pleroma_user}}-backup.sql"
+#     login_user: "{{pleroma_user}}"
+#     login_password: "{{pleroma_db_passwd}}"
+#     login_host: "{{pleroma_db_host}}"
+#   when: "{{pleroma_restore_db}}"
 
 - name: migrate db
   become: yes
@@ -78,3 +85,19 @@
 - name: enable pleroma systemd service
   systemd: name="{{pleroma_user}}" enabled="yes" state="started"
   become: yes
+
+
+# - name: backup db
+#   postgresql_db:
+#     state: "dump"
+#     db: "{{pleroma_user}}"
+#     target: "/tmp/{{pleroma_user}}-backup.sql"
+#     login_user: "{{pleroma_user}}"
+#     login_password: "{{pleroma_db_passwd}}"
+#     login_host: "{{pleroma_db_host}}"
+
+
+
+
+
+# pg_dump -U pleroma_nth_io -h pleroma.ctzpnw3lfkwz.us-east-1.rds.amazonaws.com pleroma_nth_io -f pleroma_nth_io_dump.sql
--- a/roles/pleroma/templates/prod.secret.exs.j2	Sat Jan 19 13:45:58 2019 -0600
+++ b/roles/pleroma/templates/prod.secret.exs.j2	Sun Nov 17 08:14:06 2019 -0600
@@ -27,4 +27,6 @@
   password: "{{pleroma_db_passwd}}",
   database: "{{pleroma_user}}",
   hostname: "{{pleroma_db_host}}",
-  pool_size: 10
+  pool_size: 10,
+  timeout: 60000,
+  pool_timeout: 60000
--- a/roles/pleroma/templates/setup_db.psql.j2	Sat Jan 19 13:45:58 2019 -0600
+++ b/roles/pleroma/templates/setup_db.psql.j2	Sun Nov 17 08:14:06 2019 -0600
@@ -1,6 +1,5 @@
 CREATE USER {{pleroma_user}} WITH ENCRYPTED PASSWORD '{{pleroma_db_passwd}}';
-CREATE DATABASE {{pleroma_user}};
-ALTER DATABASE {{pleroma_user}} OWNER TO {{pleroma_user}};
+CREATE DATABASE {{pleroma_user}} WITH OWNER {{pleroma_user}};
 \c {{pleroma_user}};
 --Extensions made by ecto.migrate that need superuser access
 CREATE EXTENSION IF NOT EXISTS citext;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/postgresql/defaults/main.yaml	Sun Nov 17 08:14:06 2019 -0600
@@ -0,0 +1,10 @@
+---
+
+postgresql_version: "11"
+postgresql_config_path: "/etc/postgresql/{{postgresql_version}}/main/postgresql.conf"
+postgresql_data_dir: "/var/lib/postgresql/{{postgresql_version}}/main"
+postgresql_apt_packages:
+  - "postgresql-{{postgresql_version}}"
+  - "pgcli"
+  - "postgresql-client"
+  - "postgresql-common"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/postgresql/handlers/main.yaml	Sun Nov 17 08:14:06 2019 -0600
@@ -0,0 +1,5 @@
+---
+
+- name: restart postgres
+  become: yes
+  systemd: name="postgresql" state="restarted" daemon_reload="yes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/postgresql/tasks/main.yaml	Sun Nov 17 08:14:06 2019 -0600
@@ -0,0 +1,27 @@
+---
+
+- name: install postgresql
+  become: yes
+  apt: name="{{postgresql_apt_packages}}"
+
+- name: configure postgresql data dir
+  become: yes
+  lineinfile:
+    path: "{{postgresql_config_path}}"
+    regexp: "^data_directory = "
+    line: "data_directory = '{{postgresql_data_dir}}'"
+  notify: restart postgres
+
+- name: create postgresql data dir
+  become: yes
+  file:
+    path: "{{postgresql_data_dir}}"
+    state: "directory"
+    mode: "0700"
+    owner: "postgres"
+    group: "postgres"
+  notify: restart postgres
+
+- name: ensure postgresql is started
+  become: yes
+  systemd: name="postgresql" enabled="yes" state="started"