56 lines
1.1 KiB
YAML
56 lines
1.1 KiB
YAML
|
- name: Install packages
|
||
|
package:
|
||
|
name:
|
||
|
- postgresql
|
||
|
- py3-psycopg2
|
||
|
- redis
|
||
|
|
||
|
- name: Enable services
|
||
|
service:
|
||
|
name: '{{ item }}'
|
||
|
enabled: true
|
||
|
state: started
|
||
|
loop:
|
||
|
- postgresql
|
||
|
- redis
|
||
|
|
||
|
- name: Create .pgpass
|
||
|
copy:
|
||
|
dest: '{{ user_info.home }}/.pgpass'
|
||
|
content: |
|
||
|
localhost:5432:{{ database }}:{{ user }}:{{ db_password }}
|
||
|
force: no
|
||
|
mode: 0600
|
||
|
owner: '{{ user_info.uid }}'
|
||
|
group: '{{ user_info.group }}'
|
||
|
|
||
|
- become: yes
|
||
|
become_method: su
|
||
|
become_user: postgres
|
||
|
block:
|
||
|
- name: Create database
|
||
|
postgresql_db:
|
||
|
name: '{{ database }}'
|
||
|
|
||
|
- name: Create database user
|
||
|
postgresql_user:
|
||
|
db: '{{ database }}'
|
||
|
name: '{{ user }}'
|
||
|
password: '{{ db_password }}'
|
||
|
no_password_changes: yes
|
||
|
|
||
|
- name: Set schema owner
|
||
|
postgresql_owner:
|
||
|
db: '{{ database }}'
|
||
|
new_owner: '{{ user }}'
|
||
|
obj_name: public
|
||
|
obj_type: schema
|
||
|
|
||
|
- name: Grant database privileges
|
||
|
postgresql_privs:
|
||
|
db: '{{ database }}'
|
||
|
role: '{{ user }}'
|
||
|
privs: CREATE
|
||
|
type: database
|
||
|
|