|
2 | 2 | # main file for remote DB task
|
3 | 3 | # based on https://fedoraproject.org/wiki/PostgreSQL
|
4 | 4 |
|
| 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 | + |
5 | 14 | - name: check PostgreSQL service
|
6 | 15 | service:
|
7 | 16 | name: postgresql
|
8 | 17 | state: started
|
9 | 18 | register: postgresql_status
|
10 | 19 | ignore_errors: True
|
11 | 20 |
|
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 |
| - |
26 | 21 | - name: yum install PostgreSQL
|
27 | 22 | yum:
|
28 | 23 | name: "postgresql-server"
|
29 | 24 | state: installed
|
30 | 25 | update_cache: yes
|
31 | 26 | when: postgresql_status|failed
|
32 | 27 |
|
| 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 | + |
33 | 36 | - name: run PostgreSQL initdb
|
34 | 37 | become_user: postgres
|
35 | 38 | become: yes
|
36 | 39 | shell: '/usr/bin/initdb -D /var/lib/pgsql/data'
|
| 40 | + args: |
| 41 | + creates: "/var/lib/pgsql/data/postgresql.conf" |
37 | 42 | when: postgresql_status|failed
|
38 | 43 | tags:
|
39 | 44 | - skip_ansible_lint
|
|
45 | 50 | enabled: yes
|
46 | 51 |
|
47 | 52 | # 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" |
49 | 54 | lineinfile:
|
50 | 55 | 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 }} |
51 | 59 | 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 }}" |
53 | 61 | when: ovirt_engine_remote_db == True
|
54 | 62 |
|
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" |
57 | 65 | lineinfile:
|
58 | 66 | 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 }} |
59 | 71 | 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 }}" |
61 | 73 | when: ovirt_engine_dwh_remote_db == True
|
62 | 74 |
|
63 | 75 | # listen on specific address
|
64 | 76 | - name: update postgresql.conf -> listen_addresses='*'
|
65 | 77 | lineinfile:
|
66 | 78 | dest: '/var/lib/pgsql/data/postgresql.conf'
|
67 |
| - insertafter: EOF |
| 79 | + regexp: "^listen_addresses *=.*$" |
68 | 80 | line: "listen_addresses='{{ovirt_engine_remote_db_listen_address}}'"
|
| 81 | + insertafter: EOF |
69 | 82 | when: postgresql_status|failed
|
70 | 83 |
|
71 | 84 | # listen on specific port
|
72 | 85 | - name: update postgresql.conf -> port number
|
73 | 86 | lineinfile:
|
74 | 87 | dest: '/var/lib/pgsql/data/postgresql.conf'
|
| 88 | + regexp: "^port *=.*$" |
| 89 | + line: "port={{ ovirt_engine_remote_db_port }}" |
75 | 90 | insertafter: EOF
|
76 |
| - line: "port={{ovirt_engine_remote_db_port}}" |
77 | 91 | when: postgresql_status|failed and ovirt_engine_remote_db_port != 5432
|
78 | 92 |
|
79 | 93 | # postgresql.conf: (el7)
|
|
85 | 99 | lineinfile:
|
86 | 100 | dest: '/usr/lib/systemd/system/postgresql.service'
|
87 | 101 | 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 }}" |
90 | 104 | register: port_update
|
91 | 105 | when: postgresql_status|failed and ovirt_engine_remote_db_port != 5432
|
92 | 106 | ignore_errors: True
|
|
103 | 117 | lineinfile:
|
104 | 118 | dest: '/etc/init.d/postgresql'
|
105 | 119 | 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 }}" |
108 | 122 | when: postgresql_status|failed and ovirt_engine_remote_db_port != 5432 and port_update|failed
|
109 | 123 | ignore_errors: True
|
110 | 124 |
|
111 | 125 | # allow selinux for postgresql non-standard port
|
112 | 126 | - 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 |
114 | 132 | when: postgresql_status|failed and ovirt_engine_remote_db_port != 5432
|
115 | 133 | ignore_errors: True
|
116 |
| - tags: |
117 |
| - - skip_ansible_lint |
118 | 134 |
|
119 | 135 | # first check of PostgreSQL - if fail, setup
|
120 | 136 | - name: PostgreSQL reload configuration
|
|
0 commit comments