Skip to content

Commit 1471601

Browse files
nellyclukas-bednar
authored andcommitted
Postgres new version for master (#149)
* Update main.yml * Postgres version comes from release rpms Due to ovirt-4.2 starting to work with postgres9.5 which is not officially supported in RHEL we need an extra reprository to get the relevant postgres version, the repository comes from the release rpms also removed the check if the postgres service is up, as it is not needed - the engine setup would have failed if its not * Postgres version comes from release rpms Due to ovirt-4.2 starting to work with postgres9.5 which is not officially supported in RHEL we need an extra reprository to get the relevant postgres version, the repository comes from the release rpms also removed the check if the postgres service is up, as it is not needed - the engine setup would have failed if its not * Postgres version comes from release rpms Due to ovirt-4.2 starting to work with postgres9.5 which is not officially supported in RHEL we need an extra reprository to get the relevant postgres version, the repository comes from the release rpms also removed the check if the postgres service is up, as it is not needed - the engine setup would have failed if its not * Postgres version comes from release rpms Due to ovirt-4.2 starting to work with postgres9.5 which is not officially supported in RHEL we need an extra reprository to get the relevant postgres version, the repository comes from the release rpms also removed the check if the postgres service is up, as it is not needed - the engine setup would have failed if its not
1 parent 2471687 commit 1471601

18 files changed

+121
-63
lines changed

roles/ovirt-common/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Target Systems
1111
* engine
1212
* hypervisors
1313
* dwh
14+
* database
1415

1516
Role Variables
1617
--------------

roles/ovirt-engine-remote-db/README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Target systems
1515
Requirements
1616
------------
1717

18-
Preinstalled clean operating system.
18+
Preinstalled clean environment with configured repositories.
1919

2020
Role Variables
2121
--------------
@@ -43,8 +43,6 @@ ovirt_engine_remote_db_access: # configure access to engine remote DBs
4343
address: 0.0.0.0/0 # mask for host, omitted for local
4444
method: md5 / trust / ident / peer
4545

46-
ovirt_engine_remote_db_config_file: Path to postgresql configuration
47-
(default: '/var/lib/pgsql/data/postgresql.conf')
4846
ovirt_engine_remote_db_vacuum: [True, False] True if set db configuration for
4947
vacuum feature (default: True)
5048
ovirt_engine_remote_db_vacuum_config: Default postgresql cofiguration for
@@ -54,7 +52,7 @@ ovirt_engine_remote_db_vacuum_config: Default postgresql cofiguration for
5452
Dependencies
5553
------------
5654
57-
None
55+
* ovirt-common - this is only a must on ovirt > 4.1
5856
5957
Example Playbook
6058
----------------
@@ -63,7 +61,10 @@ Example Playbook
6361
---
6462
- hosts: database
6563
vars:
66-
# vars for PostgreSQL
64+
ovirt_engine_version: "4.2"
65+
# var for ovirt-common, this is not a must for ovirt <= 4.1
66+
ovirt_rpm_repo: 'http://resources.ovirt.org/pub/yum-repo/ovirt-release41.rpm'
67+
# vars for PostgreSQL
6768
ovirt_engine_remote_db_port: 5432
6869
ovirt_engine_remote_db_listen_address: '*'
6970

@@ -86,6 +87,8 @@ Example Playbook
8687
type: local
8788
method: md5
8889
roles:
90+
# ovirt-common is not a must for ovirt <= 4.1
91+
- ovirt-common
8992
- ovirt-engine-remote-db
9093
```
9194

roles/ovirt-engine-remote-db/defaults/main.yml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ ovirt_engine_remote_db_access:
1818
address: 0.0.0.0/0
1919
method: md5
2020

21-
ovirt_engine_remote_db_config_file: "/var/lib/pgsql/data/postgresql.conf"
2221
ovirt_engine_remote_db_vacuum: true
2322
ovirt_engine_remote_db_vacuum_config:
2423
'autovacuum_vacuum_scale_factor': 0.01

roles/ovirt-engine-remote-db/tasks/main.yml

+69-44
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
# main file for remote DB task
33
# based on https://fedoraproject.org/wiki/PostgreSQL
44

5+
- name: Include postgres params
6+
include_vars: default.yml
7+
8+
- name: Override postgres params for CentOs or Red Hat when ovirt >= 4.2
9+
include_vars: postgres95.yml
10+
when:
11+
- ovirt_engine_version >= '4.2'
12+
- ansible_distribution in ('CentOS', 'Red Hat')
13+
514
# install libselinux-python on machine - selinux policy
615
- name: install SELinux requirements to run ansible modules managing SELinux.
716
yum:
@@ -11,16 +20,21 @@
1120
- libselinux-python
1221
- policycoreutils-python
1322

23+
- name: install psycopg2 requirements to run ansible modules managing postgres.
24+
yum:
25+
name: "python-psycopg2"
26+
state: "present"
27+
1428
- name: check PostgreSQL service
1529
service:
16-
name: postgresql
30+
name: "{{ postgres_service_name }}"
1731
state: started
1832
register: postgresql_status
1933
ignore_errors: True
2034

2135
- name: yum install PostgreSQL
2236
yum:
23-
name: "postgresql-server"
37+
name: "{{ postgres_server }}"
2438
state: installed
2539
update_cache: yes
2640
when: postgresql_status|failed
@@ -33,26 +47,43 @@
3347
line: 'Defaults !requiretty'
3448
when: postgresql_status|failed
3549

36-
- name: run PostgreSQL initdb
50+
- name: scl enable
51+
shell: 'scl enable rh-postgresql95 bash'
52+
when:
53+
- postgresql_status|failed
54+
- ovirt_engine_version >= '4.2'
55+
- ansible_distribution in ('CentOS', 'Red Hat')
56+
tags:
57+
- skip_ansible_lint
58+
59+
- name: run PostgreSQL DB config
3760
become_user: postgres
3861
become: yes
39-
shell: '/usr/bin/initdb -D /var/lib/pgsql/data'
62+
shell: '{{ postgres_setup_cmd }}'
4063
args:
41-
creates: "/var/lib/pgsql/data/postgresql.conf"
42-
when: postgresql_status|failed
64+
creates: "{{ postgres_config_file }}"
65+
when: ovirt_engine_version < '4.2'
66+
tags:
67+
- skip_ansible_lint
68+
69+
- name: run PostgreSQL DB config
70+
shell: '{{ postgres_setup_cmd }}'
71+
args:
72+
creates: "{{ postgres_config_file }}"
73+
when: ovirt_engine_version >= '4.2'
4374
tags:
4475
- skip_ansible_lint
4576

4677
- name: start PostgreSQL service
4778
service:
48-
name: postgresql
79+
name: "{{ postgres_service_name }}"
4980
state: started
5081
enabled: yes
5182

5283
# allow access engine database access from outside
5384
- name: "update pg_hba.conf to allow connection for ovirt_engine_remote_db"
5485
lineinfile:
55-
dest: '/var/lib/pgsql/data/pg_hba.conf'
86+
dest: '{{ postgres_data_dir }}/pg_hba.conf'
5687
line: >
5788
{{ item.type }} {{ ovirt_engine_db_name }} {{ ovirt_engine_db_user }}
5889
{{ item.address | default(' ') }} {{ item.method }}
@@ -63,7 +94,7 @@
6394
# allow access engine dwh database access from outside
6495
- name: "update pg_hba.conf to allow connection for ovirt_engine_dwh_remote_db"
6596
lineinfile:
66-
dest: '/var/lib/pgsql/data/pg_hba.conf'
97+
dest: '{{ postgres_data_dir }}/pg_hba.conf'
6798
line: >
6899
{{ item.type }} {{ ovirt_engine_dwh_db_name }}
69100
{{ ovirt_engine_dwh_db_user }} {{ item.address | default(' ') }}
@@ -75,7 +106,7 @@
75106
# listen on specific address
76107
- name: update postgresql.conf -> listen_addresses='*'
77108
lineinfile:
78-
dest: "{{ ovirt_engine_remote_db_config_file }}"
109+
dest: "{{ postgres_config_file }}"
79110
regexp: "^listen_addresses *=.*$"
80111
line: "listen_addresses='{{ovirt_engine_remote_db_listen_address}}'"
81112
insertafter: EOF
@@ -84,7 +115,7 @@
84115
# listen on specific port
85116
- name: update postgresql.conf -> port number
86117
lineinfile:
87-
dest: "{{ ovirt_engine_remote_db_config_file }}"
118+
dest: "{{ postgres_config_file }}"
88119
regexp: "^port *=.*$"
89120
line: "port={{ ovirt_engine_remote_db_port }}"
90121
insertafter: EOF
@@ -97,7 +128,7 @@
97128
# - Environment=PGPORT=5432
98129
- name: update postgresql.conf -> port number in service file (Fedora & RHEL)
99130
lineinfile:
100-
dest: '/usr/lib/systemd/system/postgresql.service'
131+
dest: '/usr/lib/systemd/system/{{ postgres_service_name }}.service'
101132
backrefs: yes
102133
regexp: "^Environment=PGPORT *=.*$"
103134
line: "Environment=PGPORT={{ ovirt_engine_remote_db_port }}"
@@ -125,7 +156,7 @@
125156
# Required for vacuum feature
126157
- name: set vacuum configuration for postgresql
127158
ini_file:
128-
path: "{{ ovirt_engine_remote_db_config_file }}"
159+
path: "{{ postgres_config_file }}"
129160
option: "{{ item.key }}"
130161
value: "{{ item.value }}"
131162
section: null
@@ -145,7 +176,7 @@
145176
# first check of PostgreSQL - if fail, setup
146177
- name: PostgreSQL reload configuration
147178
service:
148-
name: postgresql
179+
name: "{{ postgres_service_name }}"
149180
state: restarted
150181

151182
- name: check iptables service
@@ -189,45 +220,39 @@
189220
tags:
190221
- skip_ansible_lint
191222

192-
- name: creating directory for sql scripts in /tmp/ansible-sql
193-
file:
194-
path: /tmp/ansible-sql
195-
state: directory
196-
197-
- name: copy SQL scripts
198-
template:
199-
src: "{{item}}.j2"
200-
dest: "/tmp/ansible-sql/{{item}}"
201-
mode: 0644
202-
owner: postgres
203-
group: postgres
204-
with_items:
205-
- "ovirt-engine-db-create.sql"
206-
- "ovirt-engine-db-user-create.sql"
207-
- "ovirt-engine-dwh-db-create.sql"
208-
- "ovirt-engine-dwh-db-user-create.sql"
209-
210-
- name: create engine DB and user
223+
- name: create DWH DB user
224+
become: true
211225
become_user: postgres
212-
become: yes
213-
command: psql -p {{ovirt_engine_remote_db_port}} -a -f /tmp/ansible-sql/'{{item}}'
226+
postgresql_user:
227+
name: "{{ item.user }}"
228+
password: "{{ item.password }}"
214229
with_items:
215-
- "ovirt-engine-db-user-create.sql"
216-
- "ovirt-engine-db-create.sql"
217-
when: ovirt_engine_remote_db == True
230+
- user: "{{ ovirt_engine_db_user }}"
231+
password: "{{ ovirt_engine_db_password }}"
232+
- user: "{{ ovirt_engine_dwh_db_user }}"
233+
password: "{{ ovirt_engine_dwh_db_password }}"
234+
when: ovirt_engine_dwh_remote_db == True
218235

219-
- name: create engine DWH DB and user
236+
- name: create engine & DWH DBs
237+
become: true
220238
become_user: postgres
221-
become: yes
222-
command: psql -p {{ovirt_engine_remote_db_port}} -a -f /tmp/ansible-sql/'{{item}}'
239+
postgresql_db:
240+
name: "{{ item.db_name }}"
241+
owner: "{{ item.user }}"
242+
encoding: UTF-8
243+
lc_collate: en_US.UTF-8
244+
lc_ctype: en_US.UTF-8
245+
template: template0
223246
with_items:
224-
- "ovirt-engine-dwh-db-user-create.sql"
225-
- "ovirt-engine-dwh-db-create.sql"
247+
- db_name: "{{ ovirt_engine_db_name }}"
248+
user: "{{ ovirt_engine_db_user }}"
249+
- db_name: "{{ ovirt_engine_dwh_db_name }}"
250+
user: "{{ ovirt_engine_dwh_db_user }}"
226251
when: ovirt_engine_dwh_remote_db == True
227252

228253
- name: check PostgreSQL service
229254
service:
230-
name: postgresql
255+
name: "{{ postgres_service_name }}"
231256
state: started
232257
enabled: yes
233258

roles/ovirt-engine-remote-db/templates/ovirt-engine-db-create.sql.j2

-2
This file was deleted.

roles/ovirt-engine-remote-db/templates/ovirt-engine-db-user-create.sql.j2

-1
This file was deleted.

roles/ovirt-engine-remote-db/templates/ovirt-engine-dwh-db-create.sql.j2

-2
This file was deleted.

roles/ovirt-engine-remote-db/templates/ovirt-engine-dwh-db-user-create.sql.j2

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
postgres_service_name: "postgresql"
3+
postgres_server: "postgresql-server"
4+
postgres_data_dir: "/var/lib/pgsql/data"
5+
postgres_config_file: "/var/lib/pgsql/data/postgresql.conf"
6+
postgres_setup_cmd: "/usr/bin/initdb -D /var/lib/pgsql/data"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
postgres_service_name: "rh-postgresql95-postgresql"
3+
postgres_server: "rh-postgresql95-postgresql-server"
4+
postgres_data_dir: "/var/opt/rh/rh-postgresql95/lib/pgsql/data"
5+
postgres_config_file: "/var/opt/rh/rh-postgresql95/lib/pgsql/data/postgresql.conf"
6+
postgres_setup_cmd: "/opt/rh/rh-postgresql95/root/usr/bin/postgresql-setup --initdb"

roles/ovirt-engine-setup/tasks/main.yml

-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@
4444
tags:
4545
- skip_ansible_lint
4646

47-
- name: check state of database
48-
service:
49-
name: postgresql
50-
state: started
51-
when: (ovirt_engine_dwh_db_host == 'localhost' and ovirt_engine_dwh == True) or ovirt_engine_db_host == 'localhost'
52-
5347
- name: check state of engine
5448
service:
5549
name: ovirt-engine

tests/db-deploy-master.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
- name: Deploy node for ovirt-engine remote DB
3+
hosts: remote-db
4+
vars:
5+
ovirt_engine_version: "{{ ovirt_engine_version }}"
6+
ovirt_rpm_repo: "{{ ovirt_rpm_repo }}"
7+
ovirt_engine_remote_db: true
8+
ovirt_engine_dwh_remote_db: true
9+
ovirt_engine_remote_db_access:
10+
-
11+
type: host
12+
address: 0.0.0.0/0
13+
method: md5
14+
-
15+
type: local
16+
method: trust
17+
roles:
18+
- role: ovirt-common
19+
- role: ovirt-engine-remote-db

tests/test-3.6.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- include: containers-deploy.yml
33
- include: db-deploy.yml
44
vars:
5+
ovirt_engine_version: "3.6"
56
ovirt_engine_remote_db_vacuum: false
67
- include: engine-deploy.yml
78
vars:

tests/test-4.0.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- include: containers-deploy.yml
33
- include: db-deploy.yml
44
vars:
5+
ovirt_engine_version: "4.0"
56
ovirt_engine_remote_db_vacuum: false
67
- include: engine-deploy.yml
78
vars:

tests/test-4.1.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
- include: containers-deploy.yml
33
- include: db-deploy.yml
4+
vars:
5+
ovirt_engine_version: "4.1"
46
- include: engine-deploy.yml
57
vars:
68
ovirt_engine_version: "4.1"

tests/test-master.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
- include: containers-deploy.yml
3-
- include: db-deploy.yml
3+
- include: db-deploy-master.yml
4+
vars:
5+
ovirt_engine_version: "4.2"
6+
ovirt_rpm_repo: "http://plain.resources.ovirt.org/pub/yum-repo/ovirt-release-master.rpm"
47
- include: engine-deploy.yml
58
vars:
69
ovirt_engine_version: "4.2"

tests/test-upgrade-4.0-to-4.1.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
- include: containers-deploy.yml
33
- include: db-deploy.yml
4+
vars:
5+
ovirt_engine_version: "4.0"
46
- include: engine-deploy.yml
57
vars:
68
ovirt_engine_version: "4.0"

tests/test-upgrade-4.1-to-master.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
- include: containers-deploy.yml
33
- include: db-deploy.yml
4+
vars:
5+
ovirt_engine_version: "4.1"
46
- include: engine-deploy.yml
57
vars:
68
ovirt_engine_version: "4.1"

0 commit comments

Comments
 (0)