summaryrefslogtreecommitdiffstats
path: root/roles/copr/frontend/tasks/psql_setup.yml
blob: 0d8dc06db2fc07a5f6a6bef734cf6e092c4cf126 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
- name: install postresql
  yum: state=present pkg={{ item }}
  with_items:
  - "postgresql-server"
  - "postgresql-contrib"


- name: See if postgreSQL is installed
  stat: path=/var/lib/pgsql/initdb.log
  register: pgsql_installed

- name: init postgresql
  shell: "postgresql-setup initdb"
  when: not pgsql_installed.stat.exists

- name: copy pg_hba.conf
  copy: src="pg/pg_hba.conf" dest=/var/lib/pgsql/data/pg_hba.conf owner=postgres group=postgres mode=0600
  notify:
  - restart postgresql
  tags:
  - config

- name: Ensure postgres has a place to backup to
  file: dest=/backups state=directory owner=postgres
  tags:
  - config

# TODO: I think we missing user creation, check it we do it somewhere else ...

- name: Copy over backup scriplet
  copy: src="{{ files }}/../roles/postgresql_server/files/backup-database" dest=/usr/local/bin/backup-database mode=0755
  tags:
  - config

- name: Set up some cronjobs to backup databases as configured
  template: >
    src="{{ files }}/../roles/postgresql_server/templates/cron-backup-database"
    dest="/etc/cron.d/cron-backup-database-{{ item }}"
  with_items:
  - "{{ dbs_to_backup }}"
  when: dbs_to_backup != []
  tags:
  - config

- name: enable Pg service
  service: state=started enabled=yes name=postgresql

- name: Create db
  postgresql_db: name="coprdb" encoding='UTF-8'
  become: yes
  become_user: postgres

- name: Create db user
  postgresql_user: db="coprdb" name="copr-fe" password="{{ copr_database_password }}" role_attr_flags=SUPERUSER,NOCREATEDB,NOCREATEROLE
  become: yes
  become_user: postgres