Skip to content

Commit 4e3f6c5

Browse files
authored
Merge pull request #13 from TantorLabs/feature/new-certificate
Feature/new certificate
2 parents 06eb72a + 59f7d42 commit 4e3f6c5

File tree

24 files changed

+405
-293
lines changed

24 files changed

+405
-293
lines changed

README.md

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
## Project Structure
44

55
```
6-
|-- pg-cluster.yaml # Main playbook
7-
|-- pki-dir # Certificates generated using ssl-gen.sh
6+
|-- pg-cluster.yaml # Main playbook
7+
|-- pki-dir # Folder that store generated certs
88
| |-- .gitkeep
99
|-- README.md
1010
|-- inventory
@@ -17,17 +17,25 @@
1717
| | |-- prepare_nodes.yml
1818
| |-- my_inventory
1919
|-- roles
20-
| |-- etcd # Role that installs etcd-tantor-all package
20+
| |-- certificates # Role that generate TLS certs for etcd and patroni
21+
| | |-- tasks
22+
| | | `-- main.yml
23+
| | |-- vars
24+
| | | `-- main.yml
25+
| |-- etcd # Role that installs etcd-tantor-all package
2126
| | |-- handlers
2227
| | | `-- main.yml
2328
| | |-- tasks
2429
| | | |-- main.yml
2530
| | | |-- pki.yml
31+
| | | |-- cluster_add.yml
32+
| | | |-- cluster_del.yml
33+
| | | |-- cluster_state.yml
2634
| | | `-- systemd.yml
2735
| | |-- templates
2836
| | | |-- etcd.conf.j2
2937
| | | `-- etcd-tantor.service.j2
30-
| |-- haproxy # Role that installs haproxy-tantor-all package
38+
| |-- haproxy # Role that installs haproxy-tantor-all package
3139
| | |-- handlers
3240
| | | `-- main.yml
3341
| | |-- tasks
@@ -38,21 +46,25 @@
3846
| | |-- check_scripts
3947
| | | `-- chk_patroni_leader.sh
4048
| | |-- handlers
41-
| | | `-- main.yml #
49+
| | | `-- main.yml
50+
| | |-- meta
51+
| | | `-- argument_specs.yml
4252
| | |-- tasks
4353
| | | `-- main.yml
4454
| | `-- templates
4555
| | `-- keepalived.conf.j2
46-
| |-- patroni # Role that installs patroni-tantor-all package
56+
| |-- patroni # Role that installs patroni-tantor-all package
4757
| | |-- handlers
4858
| | | `-- main.yml
4959
| | |-- tasks
5060
| | | `-- main.yml
5161
| | `-- templates
52-
| | |-- patroni.service.j2
62+
| | |-- patroni_custom_bootstrap_script.sh.j2
63+
| | |-- patroni-tantor.service.j2
5364
| | |-- patroni-watchdog.service.j2
54-
| | `-- patroni.yml.j2
55-
| |-- pgbouncer # Role that installs pgbouncer-tantor-all package
65+
| | |-- patroni.yml.j2
66+
| | `-- walg.json.j2
67+
| |-- pgbouncer # Role that installs pgbouncer-tantor-all package
5668
| | |-- handlers
5769
| | | `-- main.yml
5870
| | |-- sql
@@ -62,22 +74,25 @@
6274
| | `-- templates
6375
| | |-- pgbouncer.ini.j2
6476
| | `-- pgbouncer.service.j2
65-
| |-- postgres_classic # Role that installs postgresql package
77+
| |-- postgres_classic # Role that installs postgresql package
6678
| | `-- tasks
6779
| | `-- main.yml
68-
| |-- postgres_tantordb # Role that installs tantor-server package
80+
| |-- postgres_tantordb # Role that installs tantor-server package
6981
| | `-- tasks
7082
| | `-- main.yml
71-
| `-- prepare_nodes # Role for installing basic utils
83+
| `-- prepare_nodes # Role for installing basic utils
7284
| `-- handlers
7385
| `-- main.yml
7486
| `-- tasks
75-
| `-- main.yml
87+
| |-- main.yml
88+
| |-- debian.yml
89+
| `-- rhel.yml
7690
|-- tools
77-
| |-- etcd
78-
| |-- etcd.conf
79-
| |-- pg_configurator.py
80-
| `-- ssl-gen.sh
91+
| `-- pg_cluster_backend # In progress
92+
| |-- conf
93+
| |-- log
94+
| |-- psc
95+
| `-- pg_cluster_backend.py
8196
```
8297

8398
![Architecture](pg_cluster_architechture.png)
@@ -90,7 +105,7 @@ The following text will present examples of commands to be entered in the termin
90105
## Requirements
91106

92107
Playbook requires the following component's version to be installed:
93-
* Ansible >= 2.9.10
108+
* Ansible >= 2.9.10 (with collections community.general, community.postgresql, community.crypto)
94109
* Python3 (with pip module) >= 3.10.0
95110
* psycopg2 >= 2.5.1 (it's recommended to install via pip)
96111
* packaging >= 24 (it's recommended to install via pip)
@@ -226,7 +241,7 @@ By default, the playbook does not attempt to connect to Tantor repositories and
226241
* wal-g-tantor-all
227242
* tantor DBMS
228243
229-
Pay attention to last point from the list above. Tantor package should match environment that is used during playbook launch. For example if you want to install ``tantor-be-server-15`` DBMS using command ``ansible-playbook -i inventory/my_inventory -u admin_user -e "postgresql_vendor=tantordb edition=be major_version=15" pg-cluster.yaml -K`` make sure that package ``tantor-be-server-15`` is available in your local repository.
244+
Pay attention to last point from the list above. Tantor package should match environment that is used during playbook launch. For example if you want to install ``tantor-be-server-16`` DBMS using command ``ansible-playbook -i inventory/my_inventory -u admin_user -e "postgresql_vendor=tantordb edition=be major_version=16" pg-cluster.yaml -K`` make sure that package ``tantor-be-server-16`` is available in your local repository.
230245
231246
If the playbook is run in an environment with internet access, you can leverage the most up-to-date components included in the solution. To do this, add the flag ``add_nexus_repo=true`` and provide the connection details for the repositories in the file ``inventory/group_vars/prepare_nodes.yml``.
232247
@@ -237,7 +252,7 @@ There are several options to run Ansible: with the option to install TantorDB or
237252
Use the following command to install TantorDB:
238253
239254
```bash
240-
ansible-playbook -i inventory/my_inventory -u admin_user -e "postgresql_vendor=tantordb edition=be major_version=15" pg-cluster.yaml -K
255+
ansible-playbook -i inventory/my_inventory -u admin_user -e "postgresql_vendor=tantordb edition=be major_version=16" pg-cluster.yaml -K
241256
```
242257
243258
Use the following command to install the PostgreSQL DBMS:
@@ -252,10 +267,14 @@ In the commands above, replace the value of the ``major_version`` parameter with
252267
253268
It's possible to launch the playbook with external internet access.
254269
```bash
255-
ansible-playbook -i inventory/my_inventory -u admin_user -e "postgresql_vendor=tantordb edition=be major_version=15 add_nexus_repo=true" pg-cluster.yaml -K
270+
ansible-playbook -i inventory/my_inventory -u admin_user -e "postgresql_vendor=tantordb edition=be major_version=16 add_nexus_repo=true" pg-cluster.yaml -K
256271
```
257272
In that case, make sure that connection details are provided in the file ``inventory/group_vars/prepare_nodes.yml``.
258273
274+
## Component maintenance
275+
276+
The playbook supports both full and partial updates for most components. Each role includes a variable that defines the desired version of a component (e.g., the variable ``pg_configurator_package_version`` corresponds to the ``pg-configurator-tantor-all`` component). These variables are defined in the ``inventory/group_vars`` YAML files. On the first run, the latest versions of the components will be installed. If you need to install a specific version, simply set the appropriate variable and run the playbook again.
277+
259278
## HOW TO
260279
261280
Below you can find some common commands for working with the software products included in the ``pg_cluster`` solution. Note that the commands and their result may differ depending on the software versions used.
@@ -266,10 +285,10 @@ Below you can find some common commands for working with the software products i
266285
# on NODE_1
267286
e_host=(
268287
/opt/tantor/usr/bin/etcdctl
269-
--endpoints=https://<HOST_1_IP>:2379,https://<HOST_2_IP>:2379,https://<HOST_N_IP>:2379
270-
--cacert=/opt/tantor/etc/patroni/ca.pem
271-
--cert=/opt/tantor/etc/patroni/<NODE1_HOSTNAME>.pem
272-
--key=/opt/tantor/etc/patroni/<NODE1_HOSTNAME>-key.pem
288+
--endpoints=https://$(hostname -I | awk '{print $1}'):2379
289+
--cacert=/opt/tantor/var/lib/etcd/pg-cluster.pki/ca.pem
290+
--cert=/opt/tantor/var/lib/etcd/pg-cluster.pki/$(hostname).pem
291+
--key=/opt/tantor/var/lib/etcd/pg-cluster.pki/$(hostname)-key.pem
273292
)
274293
275294
# list etcd members

ansible.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ command_timeout = 60
44
[defaults]
55
timeout = 60
66
log_path = ansible.log
7-
host_key_checking = False # отключение проверки fingerprint
7+
host_key_checking = False # отключение проверки fingerprint
8+
fail_on_error = true

inventory/group_vars/etcd.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ etcd_data_dir: /opt/tantor/var/lib/etcd
88
etcd_master_group_name: inv_etcd
99

1010
etcd_secure: True
11-
etcd_pki_dir: "{{ [ playbook_dir, 'pki-dir', hostvars[groups['inv_etcd'][0]]['ansible_hostname'] ] | path_join }}"
11+
etcd_bin_path: "/opt/tantor/usr/bin/etcdctl"
12+
etcd_conf_dir: "/opt/tantor/var/lib/etcd/pg-cluster.pki"
13+
etcd_pki_dir: "{{playbook_dir}}/pki-dir/{{ ansible_inventory_sources[0] | basename | regex_replace('\\.(ini|yml|yaml)$', '') }}"
1214
etcd_pki_key_suffix: -key.pem
1315
etcd_pki_cert_suffix: .pem
1416

inventory/group_vars/keepalived.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
keepalived_package_version: ""
33

44
# Cluster variables
5-
cluster_vip_1: "xxx.xxx.xxx.xxx"
5+
cluster_vip_1: ""
66
vip_interface: "{{ ansible_default_ipv4.interface }}" # interface name (ex. "ens32")

inventory/group_vars/patroni.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pg_configurator_package_version: ""
44
patroni_pg_exists: false #**
55
patroni_pg_port: 5432
66

7-
patroni_config_dir: /opt/tantor/etc/patroni
7+
patroni_config_dir: "/opt/tantor/etc/patroni"
88
patroni_system_user: postgres
99
patroni_system_group: postgres
1010

@@ -63,9 +63,9 @@ patroni_etcd3_srv: ""
6363
patroni_etcd3_protocol: https
6464
patroni_etcd3_username: ""
6565
patroni_etcd3_password: ""
66-
patroni_etcd3_cacert: "/opt/tantor/etc/patroni/ca.pem"
67-
patroni_etcd3_cert: "/opt/tantor/etc/patroni/{{ inventory_hostname }}.pem"
68-
patroni_etcd3_key: "/opt/tantor/etc/patroni/{{ inventory_hostname }}-key.pem"
66+
patroni_etcd3_cacert: "{{ patroni_config_dir }}/ca.pem"
67+
patroni_etcd3_cert: "{{ patroni_config_dir }}/{{ inventory_hostname }}.pem"
68+
patroni_etcd3_key: "{{ patroni_config_dir }}/{{ inventory_hostname }}-key.pem"
6969

7070
# https://patroni.readthedocs.io/en/latest/SETTINGS.html#bootstrap-configuration
7171
# dcs (Dynamic Configuration settings): This section will be written into /<namespace>/<scope>/config of the

inventory/group_vars/postgres_classic.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
config_system_locale: 'ru_RU.UTF-8'
44
config_system_language: 'en_US.UTF-8'
55
postgresql_debian_gpg_key: "https://www.postgresql.org/media/keys/ACCC4CF8.asc"
6-
major_version: 15
6+
major_version: 16

inventory/group_vars/tantordb.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22

3-
major_version: 15
3+
major_version: 16
44
edition: "be"

pg-cluster.yaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
- 'inventory/group_vars/prepare_nodes.yml'
1111
roles:
1212
- prepare_nodes
13+
any_errors_fatal: true
1314

14-
- name: Generage SSL certs for etcd
15+
- name: Generage certs
1516
hosts: localhost
1617
connection: local
1718
become: true
18-
tags: etcd
19+
tags: certificates
1920
roles:
20-
- role: etcd-ssl
21+
- role: certificates
22+
any_errors_fatal: true
2123

2224
- name: Install etcd
2325
hosts: inv_etcd
@@ -27,6 +29,7 @@
2729
- 'inventory/group_vars/etcd.yml'
2830
roles:
2931
- role: etcd
32+
any_errors_fatal: true
3033

3134
- name: Install PostgreSQL Tantordb
3235
hosts: inv_pg
@@ -37,6 +40,7 @@
3740
- 'inventory/group_vars/tantordb.yml'
3841
roles:
3942
- postgres_tantordb
43+
any_errors_fatal: true
4044

4145
- name: Install PostgreSQL Classic
4246
hosts: inv_pg
@@ -47,6 +51,7 @@
4751
- 'inventory/group_vars/postgres_classic.yml'
4852
roles:
4953
- postgres_classic
54+
any_errors_fatal: true
5055

5156
- name: Install Patroni
5257
hosts: inv_pg
@@ -59,6 +64,7 @@
5964
- 'inventory/group_vars/postgres_classic.yml'
6065
roles:
6166
- patroni
67+
any_errors_fatal: true
6268

6369
- name: Install PGBouncer
6470
hosts: inv_pg
@@ -70,6 +76,7 @@
7076
- 'inventory/group_vars/patroni.yml'
7177
roles:
7278
- pgbouncer
79+
any_errors_fatal: true
7380

7481
- name: Install Haproxy
7582
hosts: inv_pg
@@ -82,13 +89,16 @@
8289
- 'inventory/group_vars/pgbouncer.yml'
8390
roles:
8491
- haproxy
92+
any_errors_fatal: true
8593

8694
- name: Install Keepalived
8795
hosts: inv_keepalived
8896
become: true
8997
tags: keepalived
9098
vars_files:
9199
- 'inventory/group_vars/etcd.yml'
100+
- 'inventory/group_vars/patroni.yml'
92101
- 'inventory/group_vars/keepalived.yml'
93102
roles:
94103
- keepalived
104+
any_errors_fatal: true

0 commit comments

Comments
 (0)