Skip to content

Commit c312ace

Browse files
jasonodonnellJeff McCormick
authored andcommitted
Add ansible playbooks and documentation (CrunchyData#695)
1 parent c513912 commit c312ace

File tree

104 files changed

+5101
-0
lines changed

Some content is hidden

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

104 files changed

+5101
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
public
2+
.DS_Store

ansible/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Crunchy Data PostgreSQL Operator Playbook
2+
3+
<p align="center">
4+
<img src="crunchy_logo.png?raw=false" alt="Mr. Crunchy" width="150"/>
5+
</p>
6+
7+
Latest Release: 4.0.0
8+
9+
## General
10+
11+
This repository contains Ansible Roles for deploying the Crunchy PostgreSQL Operator
12+
for Kubernetes and OpenShift.
13+
14+
See the [official documentation for more information](https://crunchydata.github.io/postgres-operator-/stable/)
15+
on installing Crunchy PostgreSQL Operator.

ansible/ansible.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[defaults]
2+
retry_files_enabled = False
3+
4+
[ssh_connection]
5+
ssh_args = -o ControlMaster=no

ansible/crunchy_logo.png

394 KB
Loading

ansible/inventory

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
localhost ansible_connection=local ansible_python_interpreter="/usr/bin/env python"
2+
3+
[all:vars]
4+
5+
crunchy_debug='false'
6+
7+
# ===================
8+
# PGO Settings
9+
# The following settings configure the Crunchy PostgreSQL Operator
10+
# functionality.
11+
# ===================
12+
pgo_client_install='true'
13+
14+
# PGO Namespace
15+
pgo_namespace='pgo'
16+
target_namespaces='pgo'
17+
18+
# PGO Admin Credentials
19+
pgo_admin_username='admin'
20+
pgo_admin_password=''
21+
22+
# PGO TLS
23+
pgo_tls_no_verify='false'
24+
25+
# Crunchy Container Suite images to use. The tags centos7 and rhel7 are acceptable.
26+
ccp_image_prefix='crunchydata'
27+
ccp_image_tag='centos7-11.2-2.3.1'
28+
29+
# Crunchy PostgreSQL Operator images to use. The tags centos7 and rhel7 are acceptable.
30+
pgo_image_prefix='crunchydata'
31+
pgo_image_tag='centos7-4.0.0-rc5'
32+
33+
# This will set default enhancements for operator deployed PostgreSQL clusters
34+
auto_failover='false'
35+
backrest='false'
36+
badger='false'
37+
metrics='false'
38+
39+
# pgBackRest Defaults
40+
archive_mode='true'
41+
archive_timeout=60
42+
43+
# Log Defaults
44+
log_statement='none'
45+
log_min_duration_statement=60000
46+
47+
# Autofail Settings
48+
auto_failover_replace_replica=false
49+
auto_failover_sleep_secs=9
50+
51+
# Scheduler Settings
52+
scheduler_timeout=3600
53+
54+
# pgBackRest S3 Settings
55+
#backrest_aws_s3_key=""
56+
#backrest_aws_s3_secret=""
57+
#backrest_aws_s3_bucket=""
58+
#backrest_aws_s3_endpoint=""
59+
#backrest_aws_s3_region=""
60+
61+
# ===================
62+
# PostgreSQL Settings
63+
# Default parameters for objects created when the database container starts
64+
# such as: default database name and default username
65+
# ===================
66+
db_name='userdb'
67+
db_password_age_days=60
68+
db_password_length=20
69+
db_port=5432
70+
db_replicas=0
71+
db_user='testuser'
72+
73+
# ==================
74+
# Metrics
75+
# ==================
76+
# Optional installation of Grafana and Prometheus optimized
77+
# to work with the Crunchy PostgreSQL Operator
78+
metrics_namespace='metrics'
79+
80+
grafana_install='true'
81+
grafana_admin_username='admin'
82+
grafana_admin_password=''
83+
#grafana_storage_access_mode='ReadWriteOnce'
84+
#grafana_storage_class_name='fast'
85+
#grafana_volume_size='1G'
86+
87+
prometheus_install='true'
88+
#prometheus_storage_access_mode='ReadWriteOnce'
89+
#prometheus_storage_class_name='fast'
90+
#prometheus_volume_size='1G'
91+
92+
# ==================
93+
# Storage Settings
94+
# ==================
95+
# Which storage definitions to use when creating persistent volumes
96+
# for a variety of uses.
97+
# Note: it is suggested that backup_storage be configured to a ReadWriteMany
98+
# storage provider for pgBackRest to work correctly.
99+
backrest_storage='storage1'
100+
backup_storage='storage1'
101+
primary_storage='storage2'
102+
replica_storage='storage3'
103+
xlog_storage='storage1'
104+
105+
storage1_access_mode='ReadWriteMany'
106+
storage1_size='1G'
107+
storage1_type='dynamic'
108+
storage1_class='nfs'
109+
#storage1_supplemental_groups=65534
110+
#storage1_fs_group=26
111+
112+
storage2_access_mode='ReadWriteOnce'
113+
storage2_size='1G'
114+
storage2_type='dynamic'
115+
storage2_class='fast'
116+
#storage2_supplemental_groups=65534
117+
#storage2_fs_group=26
118+
119+
storage3_access_mode='ReadWriteOnce'
120+
storage3_size='1G'
121+
storage3_type='dynamic'
122+
storage3_class='fast'
123+
#storage3_supplemental_groups=65534
124+
#storage3_fs_group=26
125+
126+
# ==================
127+
# Deploy into Openshift
128+
# Note: openshift_token can be used for token authentication
129+
# ==================
130+
# openshift_host=''
131+
# openshift_skip_tls_verify=true
132+
# openshift_user=''
133+
# openshift_password=''
134+
135+
# ==================
136+
# Deploy into Kubernetes
137+
# ==================
138+
# kubernetes_context=''

ansible/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Deploy Crunchy PostgreSQL Operator
3+
hosts: all
4+
vars:
5+
all_namespaces: []
6+
gather_facts: true
7+
roles:
8+
- pgo-preflight
9+
- pgo-operator
10+
- pgo-metrics
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
grafana_default_dashboards: "true"
3+
grafana_port: "3000"
4+
grafana_service_name: "crunchy-grafana"
5+
6+
metrics_namespace: "crunchy-metrics"
7+
8+
prometheus_port: "9090"
9+
prometheus_service_name: "crunchy-prometheus"
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
- name: Use kubectl or oc
3+
set_fact:
4+
kubectl_or_oc: "{{ openshift_oc_bin if openshift_oc_bin is defined else 'kubectl' }}"
5+
tags:
6+
- deprovision-metrics
7+
- upgrade-metrics
8+
9+
- name: Delete Prometheus Deployment
10+
shell: |
11+
{{ kubectl_or_oc }} delete deployment crunchy-prometheus -n {{ metrics_namespace }}
12+
ignore_errors: yes
13+
no_log: false
14+
tags:
15+
- deprovision-metrics
16+
17+
- name: Delete Grafana Deployment
18+
shell: |
19+
{{ kubectl_or_oc }} delete deployment crunchy-grafana -n {{ metrics_namespace }}
20+
ignore_errors: yes
21+
no_log: false
22+
tags:
23+
- deprovision-metrics
24+
25+
- name: Delete Prometheus Service
26+
shell: |
27+
{{ kubectl_or_oc }} delete service {{ prometheus_service_name }} -n {{ metrics_namespace }}
28+
ignore_errors: yes
29+
no_log: false
30+
tags:
31+
- deprovision-metrics
32+
33+
- name: Delete Grafana Service
34+
shell: |
35+
{{ kubectl_or_oc }} delete service {{ grafana_service_name }} -n {{ metrics_namespace }}
36+
ignore_errors: yes
37+
no_log: false
38+
tags:
39+
- deprovision-metrics
40+
41+
- name: Delete Prometheus Cluster Roles
42+
shell: |
43+
{{ kubectl_or_oc }} delete clusterrole,clusterrolebinding {{ metrics_namespace }}-prometheus-sa -n {{ metrics_namespace }}
44+
ignore_errors: yes
45+
no_log: false
46+
tags:
47+
- deprovision-metrics
48+
49+
- name: Delete Prometheus Service Account
50+
shell: |
51+
{{ kubectl_or_oc }} delete serviceaccount prometheus-sa -n {{ metrics_namespace }}
52+
ignore_errors: yes
53+
no_log: false
54+
tags:
55+
- deprovision-metrics
56+
57+
- name: Delete Grafana PVC
58+
shell: |
59+
{{ kubectl_or_oc }} delete pvc grafanadata -n {{ metrics_namespace }}
60+
ignore_errors: yes
61+
no_log: false
62+
tags:
63+
- deprovision-metrics
64+
65+
- name: Delete Prometheus PVC
66+
shell: |
67+
{{ kubectl_or_oc }} delete pvc prometheusdata -n {{ metrics_namespace }}
68+
ignore_errors: yes
69+
no_log: false
70+
tags:
71+
- deprovision-metrics
72+
73+
- name: Delete Grafana Secret
74+
shell: |
75+
{{ kubectl_or_oc }} delete secret grafana-secret -n {{ metrics_namespace }}
76+
ignore_errors: yes
77+
no_log: false
78+
tags:
79+
- deprovision-metrics
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
- fail:
3+
msg: "Only set one of kubernetes_context or openshift_host"
4+
when: openshift_host is defined and kubernetes_context is defined
5+
tags: always
6+
7+
- name: Set output directory fact
8+
set_fact:
9+
grafana_output_dir: "./output/{{ metrics_namespace }}"
10+
tags: always
11+
12+
- name: Ensure output directory exists
13+
file:
14+
path: "{{ grafana_output_dir }}"
15+
state: directory
16+
mode: 0700
17+
tags: always
18+
19+
- name: Use kubectl or oc
20+
set_fact:
21+
kubectl_or_oc: "{{ openshift_oc_bin if openshift_oc_bin is defined else 'kubectl' }}"
22+
tags: always
23+
24+
- name: Deploy Grafana
25+
block:
26+
- name: Template Grafana Secret
27+
template:
28+
src: "grafana-secret.json.j2"
29+
dest: "{{ grafana_output_dir }}/grafana-secret.json"
30+
mode: '0600'
31+
tags: [install-metrics]
32+
33+
- name: Create Grafana Secret
34+
command: "{{ kubectl_or_oc }} create -f {{ grafana_output_dir }}/grafana-secret.json -n {{ metrics_namespace }}"
35+
tags: [install-metrics]
36+
37+
- name: Template Grafana Deployment
38+
template:
39+
src: "{{ item }}"
40+
dest: "{{ grafana_output_dir }}/{{ item | replace('.j2', '') }}"
41+
mode: '0600'
42+
with_items:
43+
- grafana-pvc.json.j2
44+
- grafana-service.json.j2
45+
- grafana-deployment.json.j2
46+
tags: [install-metrics]
47+
48+
- name: Create Grafana Deployment
49+
command: "{{ kubectl_or_oc }} create -f {{ grafana_output_dir }}/{{ item }} -n {{ metrics_namespace }}"
50+
with_items:
51+
- grafana-pvc.json
52+
- grafana-service.json
53+
- grafana-deployment.json
54+
tags: [install-metrics]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- name: Get Namespace Details
3+
shell: "kubectl get namespace {{ metrics_namespace }}"
4+
register: namespace_details
5+
ignore_errors: yes
6+
tags: install-metrics
7+
8+
- name: Create Namespace {{ metrics_namespace }}
9+
shell: "kubectl create namespace {{ metrics_namespace }}"
10+
when: namespace_details.rc != 0
11+
tags: install-metrics

0 commit comments

Comments
 (0)