diff --git a/roles/postgresql/tasks/main.yml b/roles/postgresql/tasks/main.yml index d2eca4f..17aecd1 100644 --- a/roles/postgresql/tasks/main.yml +++ b/roles/postgresql/tasks/main.yml @@ -1,10 +1,60 @@ --- # tasks file for postgresql -- name: Install postgres +- name: Install package dependencies package: name: - postgresql - postgresql-contrib + - python3-pip + - acl state: present update_cache: yes - become: true \ No newline at end of file + become: true +- name: Install `psycopg2` driver for postgresql + pip: + name: psycopg2-binary + state: present + become: true +- name: Update `listen_address` in `/etc/postgresql/12/main/postgresql.conf` + lineinfile: + path: /etc/postgresql/12/main/postgresql.conf + regexp: ^#listen_addresses = 'localhost' + line: listen_addresses='*' + become: true +# TODO: Copy over template `pg_hba.conf` to `/etc/postgresql/12/main/pg_hba.conf` +- name: Create new test-database + become_user: postgres + become: yes + community.postgresql.postgresql_db: + name: test +- name: Create table `test`.`message` + become_user: postgres + become: yes + community.postgresql.postgresql_table: + db: test + name: message + columns: + - id bigserial primary key + - content text +# TODO: Figure out what would be the correct `copy_from` +- name: Insert sample data into `test`.`message` + become_user: postgres + become: yes + community.postgresql.postgresql_copy: + copy_from: sample.csv + db: test + dst: message + columns: content + options: + format: csv +- name: Update password of postgres user + become_user: postgres + become: yes + community.postgresql.postgresql_user: + name: postgres + password: coolshit +- name: Restart postgresql service + service: + name: postgresql + state: restarted + enabled: yes \ No newline at end of file diff --git a/roles/postgresql/templates/sample.csv b/roles/postgresql/templates/sample.csv new file mode 100644 index 0000000..9db7df0 --- /dev/null +++ b/roles/postgresql/templates/sample.csv @@ -0,0 +1,2 @@ +hello +world \ No newline at end of file