-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# @postgres-remove | ||
--- | ||
- name: "Find out if PostgreSQL is initialized" | ||
ansible.builtin.stat: | ||
path: "/var/lib/pgsql/data/pg_hba.conf" | ||
register: postgres_data | ||
|
||
- name: "Initialize PostgreSQL" | ||
shell: "postgresql-setup --initdb" | ||
when: not postgres_data.stat.exists | ||
|
||
- name: "Start and enable services" | ||
service: "name={{ item }} state=started enabled=yes" | ||
with_items: | ||
- postgresql | ||
|
||
- name: "Install Python packages" | ||
ansible.builtin.pip: | ||
name: psycopg2-binary | ||
|
||
- name: "Create app database" | ||
postgresql_db: | ||
state: present | ||
name: "{{ tpa_single_node_pg_db }}" | ||
become: yes | ||
become_user: postgres | ||
|
||
- name: "Create db user" | ||
postgresql_user: | ||
state: present | ||
name: "{{ tpa_single_node_pg_user }}" | ||
password: "{{ tpa_single_node_pg_user_passwd }}" | ||
become: yes | ||
become_user: postgres | ||
|
||
- name: "Grant db user access to app db" | ||
postgresql_privs: | ||
type: database | ||
database: "{{ tpa_single_node_pg_db }}" | ||
roles: "{{ tpa_single_node_pg_user }}" | ||
grant_option: no | ||
privs: all | ||
become: yes | ||
become_user: postgres | ||
|
||
- name: "Ensure the IP is set to all" | ||
lineinfile: | ||
path: /var/lib/pgsql/data/postgresql.conf | ||
regexp: '^#?listen_addresses =' | ||
line: "listen_addresses = '*'" | ||
state: present | ||
|
||
- name: "Allow md5 connection for the db user" | ||
postgresql_pg_hba: | ||
dest: "/var/lib/pgsql/data/pg_hba.conf" | ||
contype: host | ||
databases: all | ||
source: 0.0.0.0/0 | ||
method: md5 | ||
users: all | ||
create: true | ||
become: yes | ||
become_user: postgres | ||
|
||
- name: Restart postgres | ||
ansible.builtin.service: | ||
name: postgresql | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters