Skip to content

Commit

Permalink
Merge pull request #25 from rmondegar/master
Browse files Browse the repository at this point in the history
Adapts the roles to includes suuport to new combination versions
  • Loading branch information
s4ke authored Mar 21, 2022
2 parents e8985eb + 4101f4f commit 9014547
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ ansible_user: "root"
postgresql_cluster_name: "main_cluster"
postgresql_cluster_port: "5433"

postgresql_cluster_version: "12"
postgresql_cluster_version: "14"
postgresql_pg_auto_failover_version: "1.6"

postgresql_cluster_hba_entries: []
#- { type: local, database: all, user: postgres, auth_method: peer }
Expand Down
1 change: 1 addition & 0 deletions roles/essential-software-setup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- python-setuptools
- python-pip
- python-passlib
- acl

- name: configure and enable ufw
remote_user: root
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: "compute monitor_nodes_list"
vars:
monitor_node_ip : "{{ hostvars[item]['host_ip'] | default(hostvars[item]['ansible_host']) }}"
set_fact:
postgresql_cluster_monitor_node_ips: "{{ (postgresql_cluster_monitor_node_ips | default([])) + [monitor_node_ip] }}"
with_items: "{{ groups['postgres_cluster'] | default([]) }}"


# TODO: add support for crl files
# FIXME: monitor port may be wrong if its overridden on a per host basis !!!
#--group {{ postgresql_cluster_group | default('0') }} \

- name: "run pg_autoctl create postgres"
become_user: "{{ postgresql_cluster_user }}"
# by default allow up to 5 hours for this command until it times out
async: "{{ postgresql_cluster_new_node_creation_timeout | default(18000) | int }}"
# poll every 10 seconds to see if we are finished
poll: 10
vars:
first_monitor_node: "{{ postgresql_cluster_monitor_node_ips | first }}"
shell: >
PATH="$PATH:{{ postgresql_cluster_bin_path }}" pg_autoctl create postgres \
--pgdata "{{ postgresql_cluster_data_dir }}" \
--skip-pg-hba \
--formation {{ postgresql_cluster_formation | default('default') }} \
--ssl-ca-file "{{ postgresql_cluster_ssl_ca_file | default('/data/ansible/certs/postgres_server/rootCA.crt') }}" \
--server-key "{{ postgresql_cluster_server_key | default('/data/ansible/certs/postgres_server/server.key') }}" \
--server-cert "{{ postgresql_cluster_server_cert | default('/data/ansible/certs/postgres_server/server.crt') }}" \
--name "{{ host_ip }}" \
--hostname "{{ host_ip }}" \
--pgport "{{ postgresql_cluster_port | default('5433') }}" \
--monitor postgres://autoctl_node@{{ first_monitor_node }}:{{ postgresql_cluster_port | default('5433') }}/pg_auto_failover
when: not (postgresql_cluster_is_monitor | default('False') | bool)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: "run pg_autoctl create monitor"
become_user: "{{ postgresql_cluster_user }}"
shell: >
PATH="$PATH:{{ postgresql_cluster_bin_path }}" pg_autoctl create monitor \
--pgdata "{{ postgresql_cluster_data_dir }}" \
--skip-pg-hba \
--ssl-ca-file "{{ postgresql_cluster_ssl_ca_file | default('/data/ansible/certs/postgres_server/rootCA.crt') }}" \
--server-key "{{ postgresql_cluster_server_key | default('/data/ansible/certs/postgres_server/server.key') }}" \
--server-cert "{{ postgresql_cluster_server_cert | default('/data/ansible/certs/postgres_server/server.crt') }}" \
--hostname "{{ host_ip }}" \
--pgport "{{ postgresql_cluster_port | default('5433') }}"
36 changes: 25 additions & 11 deletions roles/postgres-cluster-pg-auto-failover-install/files/deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,16 @@ curl_check ()

pgdg_check ()
{
echo "Checking for postgresql-12..."
if apt-cache show postgresql-12 &> /dev/null; then
echo "Detected postgresql-12..."
echo "Checking for postgresql-14..."
if apt-cache show postgresql-14 &> /dev/null; then
echo "Detected postgresql-14..."
else
pgdg_list='/etc/apt/sources.list.d/pgdg.list'
pgdg_source_path="deb http://apt.postgresql.org/pub/repos/apt/ ${codename}-pgdg main"
pgdg_key_url='https://www.postgresql.org/media/keys/ACCC4CF8.asc'

if [ -e $pgdg_list ]; then
echo "Unable to install PostgreSQL Apt Repository"
echo
echo "The file ${pgdg_list} already exists."
echo
echo "Contact us via https://www.citusdata.com/about/contact_us with information about your system for help."
exit 1
echo "Overriding ${pgdg_list}"
fi

echo -n "Installing ${pgdg_list}... "
Expand All @@ -87,6 +82,16 @@ pgdg_check ()
# import the gpg key
curl -L "${pgdg_key_url}" 2> /dev/null | apt-key add - &>/dev/null
echo "done."

echo -n "Running apt-get update... "
apt-get update &> /dev/null
echo "done."

if ! apt-cache show postgresql-14 &> /dev/null; then
echo "PGDG repositories don't have postgresql-14 package for your operating system"
echo "Cannot install Citus, exiting."
exit 1
fi
fi
}

Expand Down Expand Up @@ -166,6 +171,9 @@ detect_codename ()
10)
codename='buster'
;;
11)
codename='bullseye'
;;
wheezy)
codename="${dist}"
;;
Expand All @@ -178,6 +186,9 @@ detect_codename ()
buster)
codename="${dist}"
;;
bullseye)
codename="${dist}"
;;
*)
unknown_os
;;
Expand Down Expand Up @@ -216,6 +227,7 @@ main ()
apt_config_url="https://repos.citusdata.com/community/config_file.list?os=${os}&dist=${dist}&source=script"

apt_source_path="/etc/apt/sources.list.d/citusdata_community.list"
gpg_keyring_path="/usr/share/keyrings/citusdata_community-archive-keyring.gpg"

echo -n "Installing $apt_source_path... "

Expand Down Expand Up @@ -259,9 +271,11 @@ main ()
echo "done."
fi

echo -n "Importing Citus Data gpg key... "
echo -n "Importing Citus Data Community gpg key... "
# import the gpg key
curl -L "${gpg_key_url}" 2> /dev/null | apt-key add - &>/dev/null
# below command decodes the ASCII armored gpg file (instead of binary file)
# and adds the unarmored gpg key as keyring
curl -fsSL "${gpg_key_url}" | gpg --dearmor > ${gpg_keyring_path}
echo "done."

echo -n "Running apt-get update... "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
command: "bash /tmp/pg_auto_failover_deb.sh"
when: not pgdata_dir_version.stat.exists

- name: "install postgresql-{{ postgresql_cluster_version }}-auto-failover-{{ postgresql_pg_auto_failover_version }}"
- name: "install pg-auto-failover-cli-{{ postgresql_pg_auto_failover_version }}"
apt:
name: "postgresql-{{ postgresql_cluster_version }}-auto-failover-{{ postgresql_pg_auto_failover_version }}"
name: "pg-auto-failover-cli-{{ postgresql_pg_auto_failover_version }}"
state: present
update_cache: "{{ apt_update_cache | default('True') }}"
when: not pgdata_dir_version.stat.exists

- name: "install pg-auto-failover-cli-{{ postgresql_pg_auto_failover_version }}"
- name: "install postgresql-{{ postgresql_cluster_version }}-auto-failover-{{ postgresql_pg_auto_failover_version }}"
apt:
name: "pg-auto-failover-cli-{{ postgresql_pg_auto_failover_version }}"
name: "postgresql-{{ postgresql_cluster_version }}-auto-failover-{{ postgresql_pg_auto_failover_version }}"
state: present
update_cache: "{{ apt_update_cache | default('True') }}"
when: not pgdata_dir_version.stat.exists

0 comments on commit 9014547

Please sign in to comment.