summaryrefslogtreecommitdiffstats
path: root/roles/postgresql_server/tasks/main.yml
blob: 704ad6d8bb7d447bd2fffa51425ca9ef75ad97a8 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
#
# Setup postgresql server. 
#
- name: install postgresql server packages
  yum: name={{ item }}  state=present
  with_items:
  - postgresql-server
  - postgresql-contrib
  - postgresql-plpython
  - python-psycopg2
  tags:
  - packages
  - postgresql

- name: Set kernel shared memory max to a larger value
  sysctl: name=kernel.shmmax value={{ kernel_shmmax }}
  when: kernel_shmmax is defined
  notify:
  - restart postgresql
  tags:
  - postgresql

- name: Initialize postgres if necessary
  command: /usr/bin/postgresql-setup initdb
           creates=/var/lib/pgsql/data
  notify:
  - restart postgresql
  tags:
  - postgresql

- name: Set postgresql-server to run on boot
  service: name=postgresql enabled=yes
  ignore_errors: true
  notify:
  - restart postgresql
  tags:
  - service
  - postgresql

- name: Add our postgres config file.
  copy: >
    src={{ item }}
    dest=/var/lib/pgsql/data/{{ item }}
    owner=postgres
  with_items:
  - pg_hba.conf
  notify:
  - restart postgresql
  tags:
  - config
  - postgresql

- name: postgresql config template
  template: dest=/var/lib/pgsql/data/postgresql.conf src=postgresql.conf
  notify:
  - restart postgresql
  tags:
  - config
  - postgresql

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

- name: Copy over backup scriplet
  copy: src=backup-database dest=/usr/local/bin/backup-database mode=0755
  tags:
  - postgresql

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

- name: Set up a cron job to clean long koji sessions on koji database server only
  copy: >
    src=koji-cleanup-sessions.cron
    dest=/etc/cron.d/koji-cleanup-sessions.cron
  when: inventory_hostname.startswith('db-koji01')
  tags:
  - cron
  - postgresql

- name: Set up a script for cron job to clean long fas sessions on fas database server only
  copy: >
    src=fasdb-cleanup-sessions
    dest=/usr/local/bin/fasdb-cleanup-sessions
    mode=755
  when: inventory_hostname.startswith('db-fas01')
  tags:
  - cron
  - postgresql

- name: Set up a cron job to clean long fas sessions on fas database server only
  copy: >
    src=fasdb-cleanup-sessions.cron
    dest=/etc/cron.d/fasdb-cleanup-sessions.cron
  when: inventory_hostname.startswith('db-fas01')
  tags:
  - cron
  - postgresql