diff --git a/ansible1/.yamllint b/ansible1/.yamllint new file mode 100644 index 000000000..8c1c4ca75 --- /dev/null +++ b/ansible1/.yamllint @@ -0,0 +1,11 @@ +--- +extends: default + +rules: + line-length: + max: 120 + level: warning + +ignore: | + .github/workflows/ci.yml + .github/workflows/cd.yml \ No newline at end of file diff --git a/ansible1/playbook-develop-ubuntu.yml b/ansible1/playbook-develop-ubuntu.yml index 365551367..5d5b4b814 100644 --- a/ansible1/playbook-develop-ubuntu.yml +++ b/ansible1/playbook-develop-ubuntu.yml @@ -6,3 +6,4 @@ become_user: root roles: - packages + - postgresql diff --git a/ansible1/roles/packages/handlers/main.yml b/ansible1/roles/packages/handlers/main.yml deleted file mode 100644 index 5206c9821..000000000 --- a/ansible1/roles/packages/handlers/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -- name: Reload shell - shell: exec $SHELL diff --git a/ansible1/roles/postgresql/handlers/main.yml b/ansible1/roles/postgresql/handlers/main.yml new file mode 100644 index 000000000..0d7e5b861 --- /dev/null +++ b/ansible1/roles/postgresql/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: restart postgresql + service: + name: postgresql + state: restarted diff --git a/ansible1/roles/postgresql/tasks/main.yml b/ansible1/roles/postgresql/tasks/main.yml new file mode 100644 index 000000000..17ac52df1 --- /dev/null +++ b/ansible1/roles/postgresql/tasks/main.yml @@ -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 diff --git a/ansible1/roles/postgresql/vars/main.yml b/ansible1/roles/postgresql/vars/main.yml new file mode 100644 index 000000000..f7d085ebe --- /dev/null +++ b/ansible1/roles/postgresql/vars/main.yml @@ -0,0 +1,5 @@ +--- +postgres_user: "postgres" +postgres_db_development_name: "zero_waste_development" +postgres_db_test_name: "zero_waste_test" +postges_version: 12