Skip to content

Commit 9019c7e

Browse files
committed
add role "consul"
1 parent d85d10e commit 9019c7e

File tree

110 files changed

+7137
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+7137
-14
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

consul.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
3+
- hosts: consul_instances
4+
become: true
5+
become_method: sudo
6+
any_errors_fatal: true
7+
gather_facts: true
8+
vars_files:
9+
- vars/main.yml
10+
- vars/system.yml
11+
12+
pre_tasks:
13+
- name: Include OS-specific variables
14+
include_vars: "vars/{{ ansible_os_family }}.yml"
15+
when: not ansible_os_family == 'Rocky' and not ansible_os_family == 'AlmaLinux'
16+
tags: always
17+
18+
# For compatibility with Ansible old versions
19+
# (support for RockyLinux and AlmaLinux has been added to Ansible 2.11)
20+
- name: Include OS-specific variables
21+
include_vars: "vars/RedHat.yml"
22+
when: ansible_os_family == 'Rocky' or ansible_os_family == 'AlmaLinux'
23+
tags: always
24+
25+
- name: Update apt cache
26+
apt:
27+
update_cache: true
28+
cache_valid_time: 3600
29+
environment: "{{ proxy_env | default({}) }}"
30+
when: ansible_os_family == "Debian" and installation_method == "repo"
31+
32+
- name: Make sure the gnupg and apt-transport-https packages are present
33+
apt:
34+
pkg:
35+
- gnupg
36+
- apt-transport-https
37+
state: present
38+
environment: "{{ proxy_env | default({}) }}"
39+
when: ansible_os_family == "Debian" and installation_method == "repo"
40+
41+
- name: Build a firewall_ports_dynamic_var
42+
set_fact:
43+
firewall_ports_dynamic_var: "{{ firewall_ports_dynamic_var | default([]) + (firewall_allowed_tcp_ports_for[item]) }}"
44+
loop: "{{ hostvars[inventory_hostname].group_names }}"
45+
when: firewall_enabled_at_boot|bool
46+
tags: firewall
47+
48+
- name: Build a firewall_rules_dynamic_var
49+
set_fact:
50+
firewall_rules_dynamic_var: "{{ firewall_rules_dynamic_var | default([]) + (firewall_additional_rules_for[item]) }}"
51+
loop: "{{ hostvars[inventory_hostname].group_names }}"
52+
when: firewall_enabled_at_boot|bool
53+
tags: firewall
54+
55+
roles:
56+
- role: ansible-role-firewall
57+
environment: "{{ proxy_env | default({}) }}"
58+
vars:
59+
firewall_allowed_tcp_ports: "{{ firewall_ports_dynamic_var | unique }}"
60+
firewall_additional_rules: "{{ firewall_rules_dynamic_var | unique }}"
61+
when: firewall_enabled_at_boot|bool
62+
tags: firewall
63+
64+
- role: hostname
65+
- role: etc_hosts
66+
- role: timezone
67+
- role: ntp
68+
69+
- role: consul
70+
71+
...

deploy_pgcluster.yml

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
when: not dcs_exists|bool and dcs_type == "etcd"
2323
tags: etcd
2424

25+
- import_playbook: consul.yml
26+
when: not dcs_exists|bool and dcs_type == "consul"
27+
tags: consul
28+
2529
- hosts: postgres_cluster
2630
become: true
2731
become_method: sudo

inventory

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
# This is example inventory file!
21
# Please specify the ip addresses and connection settings for your environment
32
# The specified ip addresses will be used to listen by the cluster components.
43

54
# "postgresql_exists='true'" if PostgreSQL is already exists and running
65
# "hostname=" variable is optional (used to change the server name)
76

8-
# if dcs_exists: false and dcs_type: "etcd" (in vars/main.yml)
9-
[etcd_cluster] # recommendation: 3 or 5-7 nodes
7+
# In this example, all components will be installed on PostgreSQL nodes.
8+
# You can deploy the haproxy balancers and the etcd or consul cluster on other dedicated servers (recomended).
9+
10+
# if dcs_exists: false and dcs_type: "etcd"
11+
[etcd_cluster] # recommendation: 3, or 5-7 nodes
1012
10.128.64.140
1113
10.128.64.142
1214
10.128.64.143
1315

16+
# if dcs_exists: false and dcs_type: "consul"
17+
[consul_instances] # recommendation: 3 or 5-7 nodes
18+
10.128.64.140 consul_datacenter=dc1 consul_node_role=server consul_bootstrap_expect=true
19+
10.128.64.142 consul_datacenter=dc1 consul_node_role=server consul_bootstrap_expect=true
20+
10.128.64.143 consul_datacenter=dc1 consul_node_role=server consul_bootstrap_expect=true
21+
#10.128.64.144 consul_node_role=client
22+
#10.128.64.145 consul_node_role=client
1423

15-
# if with_haproxy_load_balancing: true (in vars/main.yml)
24+
# if with_haproxy_load_balancing: true
1625
[balancers]
1726
10.128.64.140
1827
10.128.64.142
1928
10.128.64.143
2029

21-
2230
# PostgreSQL nodes
2331
[master]
2432
10.128.64.140 hostname=pgnode01 postgresql_exists='false'
@@ -31,12 +39,7 @@
3139
master
3240
replica
3341

34-
35-
# In this example, all components will be installed on PostgreSQL nodes
36-
# You can deploy the etcd cluster and the haproxy balancers on other dedicated servers.
37-
38-
39-
# if pgbackrest_install: true and "repo_host" is set (in vars/main.yml)
42+
# if pgbackrest_install: true and "repo_host" is set
4043
[pgbackrest] # optional (Dedicated Repository Host)
4144

4245

@@ -46,8 +49,8 @@ ansible_connection='ssh'
4649
ansible_ssh_port='22'
4750
ansible_user='root'
4851
ansible_ssh_pass='secretpassword' # "sshpass" package is required for use "ansible_ssh_pass"
49-
# ansible_ssh_private_key_file=
50-
# ansible_python_interpreter='/usr/bin/python3' # is required for use python3
52+
#ansible_ssh_private_key_file=
53+
#ansible_python_interpreter='/usr/bin/python3' # is required for use python3
5154

5255
[pgbackrest:vars]
5356
ansible_user='postgres'

0 commit comments

Comments
 (0)