Skip to content

Commit

Permalink
add postgres config
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiKhomik committed Dec 6, 2024
1 parent 64b5c3a commit a86a1a8
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
11 changes: 11 additions & 0 deletions ansible1/.yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
extends: default

rules:
line-length:
max: 120
level: warning

ignore: |
.github/workflows/ci.yml
.github/workflows/cd.yml
1 change: 1 addition & 0 deletions ansible1/playbook-develop-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
become_user: root
roles:
- packages
- postgresql
3 changes: 0 additions & 3 deletions ansible1/roles/packages/handlers/main.yml

This file was deleted.

5 changes: 5 additions & 0 deletions ansible1/roles/postgresql/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: restart postgresql
service:
name: postgresql
state: restarted
66 changes: 66 additions & 0 deletions ansible1/roles/postgresql/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
- name: Install packages
apt: "name={{ item }} state=present"
with_items:
- postgresql
- postgresql-server

- name: Install Python packages
pip: "name={{ item }} state=present"
sudo: yes
with_items:
- postgresql-{{ postges_version }}
- postgresql-client-{{ postges_version }}
- postgresql-contrib-{{ postges_version }}

- name: Configure PostgreSQL. Set listen_address
lineinfile: dest=/etc/postgresql/{{ postges_version }}/main/postgresql.conf
regexp="max_connections =" line="max_connections = 1000" state=present
notify: restart postgresql
sudo: yes

- name: Configure PostgreSQL. Set SSL
lineinfile: dest=/etc/postgresql/{{ postges_version }}/main/postgresql.conf
regexp="ssl =" line="ssl = false" state=present
notify: restart postgresql
sudo: yes

- name: Configure PostgreSQL. Set autovacuum
lineinfile: dest=/etc/postgresql/{{ postges_version }}/main/postgresql.conf
regexp="autovacuum =" line="autovacuum = on" state=present
notify: restart postgresql
sudo: yes

- name: Configure PostgreSQL. Set hosts in pg_hba.conf
template:
src=pg_hba.conf.j2 dest=/etc/postgresql/{{ postgresql_version }}/main/pg_hba.conf
backup=yes
notify: restart postgresql
sudo: yes

- name: Install psycopg2
pip: name=psycopg2
sudo: yes

- name: Create PostgreSQL DB
postgresql_db: name={{ postgres_db_development_name }}
sudo: yes
sudo_user: { { postgres_user } }

- name: Create PostgreSQL DB
postgresql_db: name={{ postgres_db_test_name }}
sudo: yes
sudo_user: { { postgres_user } }

- name: Include encrypted secrets
include_vars:
file: vars/secrets.yml

- name: Create PostgreSQL user and grant access
postgresql_user: db={{ postgres_db_development_name }} user={{ postgres_user }} password={{ postgres_user_password }}
sudo: yes
sudo_user: { { postgres_user } }

- name: Run rake db:migrate
shell: |
rake db:migrate
5 changes: 5 additions & 0 deletions ansible1/roles/postgresql/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
postgres_user: "postgres"
postgres_db_development_name: "zero_waste_development"
postgres_db_test_name: "zero_waste_test"
postges_version: 12

0 comments on commit a86a1a8

Please sign in to comment.