Skip to content

Commit dbbdc65

Browse files
authored
remote-db: added option to customize access to remote db (#111)
1) added option to customize access to remote db some time we need to grant access from local, and also restrict subnet from where the connection can be established from. 2) update test that it use remote deployment of db it create separate container and deploy remote db there for engine and dwh.
1 parent 406f5e0 commit dbbdc65

File tree

6 files changed

+103
-39
lines changed

6 files changed

+103
-39
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ ovirt_engine_db_password: password for user of ovirt-engine DB
3636
ovirt_engine_dwh_db_name: DB name for ovirt-engine-dwh (default: 'ovirt_engine_history')
3737
ovirt_engine_dwh_db_user: DB user which can access ovirt-engine-dwh DB (default: 'ovirt_engine_history')
3838
ovirt_engine_dwh_db_password: password for user of ovirt-engine DB
39+
40+
ovirt_engine_remote_db_access: # configure access to engine remote DBs
41+
-
42+
type: host / local
43+
address: 0.0.0.0/0 # mask for host, omitted for local
44+
method: md5 / trust / ident / peer
3945
```
4046
4147
Dependencies
@@ -64,6 +70,14 @@ Example Playbook
6470
ovirt_engine_dwh_db_name: 'ovirt_engine_history'
6571
ovirt_engine_dwh_db_user: 'ovirt_engine_history'
6672
ovirt_engine_dwh_db_password: 123456
73+
ovirt_engine_remote_db_access:
74+
-
75+
type: host
76+
address: 0.0.0.0/0
77+
method: md5
78+
-
79+
type: local
80+
method: md5
6781
roles:
6882
- ovirt-engine-remote-db
6983
```

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

+8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@ ovirt_engine_remote_db_port: 5432
33
ovirt_engine_remote_db_listen_address: '*'
44
ovirt_engine_db_name: 'engine'
55
ovirt_engine_db_user: 'engine'
6+
ovirt_engine_db_password: 'AqbXg4dpkbcVRZwPbY8WOR'
67

78
ovirt_engine_remote_db: False
89
ovirt_engine_dwh_remote_db: False
910

1011
ovirt_engine_dwh_db_name: 'ovirt_engine_history'
1112
ovirt_engine_dwh_db_user: 'ovirt_engine_history'
13+
ovirt_engine_dwh_db_password: '37xmBKECANQGm0z3SfylMp'
14+
15+
ovirt_engine_remote_db_access:
16+
-
17+
type: host
18+
address: 0.0.0.0/0
19+
method: md5

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

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

5+
# install libselinux-python on machine - selinux policy
6+
- name: install SELinux requirements to run ansible modules managing SELinux.
7+
yum:
8+
name: "{{ item }}"
9+
state: "present"
10+
with_items:
11+
- libselinux-python
12+
- policycoreutils-python
13+
514
- name: check PostgreSQL service
615
service:
716
name: postgresql
817
state: started
918
register: postgresql_status
1019
ignore_errors: True
1120

12-
# install libselinux-python on machine - selinux policy
13-
- name: install libselinux-python for ansible
14-
yum:
15-
name: libselinux-python
16-
state: "present"
17-
when: postgresql_status|failed
18-
19-
# for semanage utility
20-
- name: install policycoreutils-python for changing selinux port
21-
yum:
22-
name: policycoreutils-python
23-
state: "present"
24-
when: postgresql_status|failed
25-
2621
- name: yum install PostgreSQL
2722
yum:
2823
name: "postgresql-server"
2924
state: installed
3025
update_cache: yes
3126
when: postgresql_status|failed
3227

28+
- name: enable sudo without tty
29+
lineinfile:
30+
path: /etc/sudoers
31+
state: present
32+
regexp: '^Defaults *requiretty$'
33+
line: 'Defaults !requiretty'
34+
when: postgresql_status|failed
35+
3336
- name: run PostgreSQL initdb
3437
become_user: postgres
3538
become: yes
3639
shell: '/usr/bin/initdb -D /var/lib/pgsql/data'
40+
args:
41+
creates: "/var/lib/pgsql/data/postgresql.conf"
3742
when: postgresql_status|failed
3843
tags:
3944
- skip_ansible_lint
@@ -45,35 +50,44 @@
4550
enabled: yes
4651

4752
# allow access engine database access from outside
48-
- name: update pg_hba.conf -> host ovirt_engine_db_name ovirt_engine_db_user 0.0.0.0/0 md5
53+
- name: "update pg_hba.conf to allow connection for ovirt_engine_remote_db"
4954
lineinfile:
5055
dest: '/var/lib/pgsql/data/pg_hba.conf'
56+
line: >
57+
{{ item.type }} {{ ovirt_engine_db_name }} {{ ovirt_engine_db_user }}
58+
{{ item.address | default(' ') }} {{ item.method }}
5159
insertafter: EOF
52-
line: "host {{ovirt_engine_db_name}} {{ovirt_engine_db_user}} 0.0.0.0/0 md5"
60+
with_items: "{{ ovirt_engine_remote_db_access | list }}"
5361
when: ovirt_engine_remote_db == True
5462

55-
# allow access dwh database access from outside
56-
- name: update pg_hba.conf -> host ovirt_engine_db_dwh_name ovirt_engine_db_dwh_user 0.0.0.0/0 md5
63+
# allow access engine dwh database access from outside
64+
- name: "update pg_hba.conf to allow connection for ovirt_engine_dwh_remote_db"
5765
lineinfile:
5866
dest: '/var/lib/pgsql/data/pg_hba.conf'
67+
line: >
68+
{{ item.type }} {{ ovirt_engine_dwh_db_name }}
69+
{{ ovirt_engine_dwh_db_user }} {{ item.address | default(' ') }}
70+
{{ item.method }}
5971
insertafter: EOF
60-
line: "host {{ovirt_engine_dwh_db_name}} {{ovirt_engine_dwh_db_user}} 0.0.0.0/0 md5"
72+
with_items: "{{ ovirt_engine_remote_db_access | list }}"
6173
when: ovirt_engine_dwh_remote_db == True
6274

6375
# listen on specific address
6476
- name: update postgresql.conf -> listen_addresses='*'
6577
lineinfile:
6678
dest: '/var/lib/pgsql/data/postgresql.conf'
67-
insertafter: EOF
79+
regexp: "^listen_addresses *=.*$"
6880
line: "listen_addresses='{{ovirt_engine_remote_db_listen_address}}'"
81+
insertafter: EOF
6982
when: postgresql_status|failed
7083

7184
# listen on specific port
7285
- name: update postgresql.conf -> port number
7386
lineinfile:
7487
dest: '/var/lib/pgsql/data/postgresql.conf'
88+
regexp: "^port *=.*$"
89+
line: "port={{ ovirt_engine_remote_db_port }}"
7590
insertafter: EOF
76-
line: "port={{ovirt_engine_remote_db_port}}"
7791
when: postgresql_status|failed and ovirt_engine_remote_db_port != 5432
7892

7993
# postgresql.conf: (el7)
@@ -85,8 +99,8 @@
8599
lineinfile:
86100
dest: '/usr/lib/systemd/system/postgresql.service'
87101
backrefs: yes
88-
regexp: "Environment=PGPORT=5432"
89-
line: "Environment=PGPORT={{ovirt_engine_remote_db_port}}"
102+
regexp: "^Environment=PGPORT *=.*$"
103+
line: "Environment=PGPORT={{ ovirt_engine_remote_db_port }}"
90104
register: port_update
91105
when: postgresql_status|failed and ovirt_engine_remote_db_port != 5432
92106
ignore_errors: True
@@ -103,18 +117,20 @@
103117
lineinfile:
104118
dest: '/etc/init.d/postgresql'
105119
backrefs: yes
106-
regexp: "PGPORT=5432"
107-
line: "PGPORT={{ovirt_engine_remote_db_port}}"
120+
regexp: "^PGPORT *=.*$"
121+
line: "PGPORT={{ ovirt_engine_remote_db_port }}"
108122
when: postgresql_status|failed and ovirt_engine_remote_db_port != 5432 and port_update|failed
109123
ignore_errors: True
110124

111125
# allow selinux for postgresql non-standard port
112126
- name: allow selinux for non-standard port
113-
shell: 'semanage port -a -t postgresql_port_t -p tcp {{ovirt_engine_remote_db_port}}'
127+
seport:
128+
ports: "{{ ovirt_engine_remote_db_port }}"
129+
proto: "tcp"
130+
setype: "postgresql_port_t"
131+
state: present
114132
when: postgresql_status|failed and ovirt_engine_remote_db_port != 5432
115133
ignore_errors: True
116-
tags:
117-
- skip_ansible_lint
118134

119135
# first check of PostgreSQL - if fail, setup
120136
- name: PostgreSQL reload configuration

tests/inventory

+6
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
localhost ansible_connection=local ansible_python_interpreter="/usr/bin/env python"
2+
3+
[engine]
4+
engine_centos7 image="chrismeyers/centos7"
5+
6+
[remote-db]
7+
remote_db_centos7 image="chrismeyers/centos7"

tests/test.yml

+30-10
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,43 @@
22
- name: Bring up docker containers
33
hosts: localhost
44
gather_facts: false
5-
vars:
6-
inventory:
7-
- name: engine_centos7
8-
image: "chrismeyers/centos7"
95
roles:
106
- role: provision_docker
11-
provision_docker_inventory: "{{ inventory }}"
7+
provision_docker_inventory_group: "{{ groups['remote-db'] }}"
8+
- role: provision_docker
9+
provision_docker_inventory_group: "{{ groups['engine'] }}"
10+
11+
12+
- name: Deploy node for ovirt-engine remote DB
13+
hosts: remote-db
14+
vars:
15+
ovirt_engine_remote_db: True
16+
ovirt_engine_dwh_remote_db: True
17+
ovirt_engine_remote_db_access:
18+
-
19+
type: host
20+
address: 0.0.0.0/0
21+
method: md5
22+
-
23+
type: local
24+
method: trust
25+
roles:
26+
- role: ovirt-engine-remote-db
1227

1328

1429
- name: Run ovirt-ansible roles on containerized environments
15-
hosts: docker_containers
30+
hosts: engine
1631
vars:
1732
ovirt_engine_type: "ovirt-engine"
1833
ovirt_engine_version: "4.1"
1934
ovirt_rpm_repo: "http://plain.resources.ovirt.org/pub/yum-repo/ovirt-release41.rpm"
20-
ovirt_engine_dwh: True
21-
ovirt_engine_configure_iso_domain: True
2235
ovirt_engine_hostname: "localhost"
2336
ovirt_engine_organization: "example.com"
2437
ovirt_engine_admin_password: "123456"
38+
ovirt_engine_db_host: "{{ hostvars['remote_db_centos7']['ansible_default_ipv4']['address'] }}"
39+
ovirt_engine_dwh: True
40+
ovirt_engine_dwh_db_host: "{{ hostvars['remote_db_centos7']['ansible_default_ipv4']['address'] }}"
41+
ovirt_engine_configure_iso_domain: True
2542
ovirt_engine_firewall_manager: null
2643
ovirt_engine_config:
2744
-
@@ -41,12 +58,15 @@
4158
- role: ovirt-iso-uploader-conf
4259
# - role: ovirt-collect-logs # Issue #102
4360

61+
4462
- name: Run ovirt-engine-cleanup on containerized environments
45-
hosts: docker_containers
63+
hosts: engine
4664
vars:
4765
ovirt_engine_type: "ovirt-engine"
4866
ovirt_engine_version: "4.1"
49-
ovirt_engine_dwh: True
5067
ovirt_engine_hostname: "localhost"
68+
ovirt_engine_db_host: "{{ hostvars['remote_db_centos7']['ansible_default_ipv4']['address'] }}"
69+
ovirt_engine_dwh: True
70+
ovirt_engine_dwh_db_host: "{{ hostvars['remote_db_centos7']['ansible_default_ipv4']['address'] }}"
5171
roles:
5272
- role: ovirt-engine-cleanup # This role must be last

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ commands =
3737
{[testenv:yamllint]commands}
3838
{[testenv:ansible-syntax]commands}
3939
{[testenv:ansible-lint]commands}
40-
{[testenv:flake8]commands}
40+
{[testenv:flake8]commands}

0 commit comments

Comments
 (0)