This Ansible Galaxy Role contains task files that assist in the management of CloudNativePG and EDB Postgres for Kubernetes.
The ansible playbook must be executed under an account that has full privileges.
The only dependencies required for this ansible galaxy role are:
- AWS EKS CLI, Azure CLI, or Google Cloud CLI - Depends directly on the target cloud
- Kubectl
- Ansible
- Python packages:
openshift,pyyaml,kubernetesandpyhelm; Installed with commands:pip install openshift pyyaml kubernetespip install pyhelm kubernetes.core.k8s- Ansible Module - Required for Kubernetes.- CloudNativePG PlugIn is required for:
promote-pod,reload-cluster,restart-cluster,restart-pod,maintenance-set,maintenance-unsetandstatus-cluster.
cnpg_task must be defined with a value in order to indicate which task in the role will be executed.
The options are:
add-db,add-schema,add-roledrop-db,drop-schema,drop-roleexecute-sql-scriptapply-manifest,remove-manifestconfigure-memory,configure-pg-hbascale-replicasget-superuser-secret,add-postgres-expose-service,drop-postgres-expose-serviceadd-grafana-expose-service,drop-grafana-expose-servicepromote-podreload-cluster,restart-cluster,restart-podmaintenance-set,maintenance-unsetstatus-cluster
The manage_cnpg role does not have any dependencies on any other roles.
Below is an example of how to include the manage_cnpg role:
---
- name: Manage a CloudNativePG or CloudNative Postgres Cluster Playbook
hosts: localhost
gather_facts: false
any_errors_fatal: true
collections:
- edb_devops.edb_postgres
pre_tasks:
- name: Initialize the user defined variables
ansible.builtin.set_fact:
# Options"
# add-db, add-schema, add-role
# drop-db, drop-schema, drop-role
# execute-sql-script
# apply-manifest, remove-manifest
# configure-memory, configure-pg-hba
cnpg_task:
- drop-role
# CloudNativePG Namespace
cnpg_namespace: default
# CloudNativePG Cluster Name
cluster_name: cluster-example
# CloudNativePG Pod Name
pod_name: cluster-example-2
# Databases
db_name: edb
# Schemas
schema_name: edb_schema
# Roles
db_role: edb_role
db_role_password: admin
# SQL Script
sql_script: DROP DATABASE {{ db_name }};
# Manifest Filename
manifest_filename: configure_memory.yml
# Scale Replicas Number
scale_replicas_to: 3
# Scale Manifest Filename
scale_manifest_filename: roles/manage_cnpg/files/cluster-example.yml
roles:
- role: manage_cnpg
when: cnpg_task is definedA previously provisioned Cloud Kubernetes Cluster is required. The steps below will retrieve the credentials and update the local kubeconfig file.
# Update local kubeconfig with Cloud Kubernetes Cluster credentials
$ eksctl get nodegroup --cluster <k8s-cluster-name># Update local kubeconfig with Cloud Kubernetes Cluster credentials
$ az aks get-credentials --resource-group <k8s-resource-group> --name <k8s-cluster-name># Update local kubeconfig with Cloud Kubernetes Cluster credentials
$ gcloud container clusters get-credentials <k8s-cluster-name> --region <gcloud-region>Copy the manage_cnpg.yml playbook located in the playbook-examples/manage_cvnpg directory into the root of the edb-ansible directory.
Navigate towards: 'https://cloudnative-pg.io/documentation/1.19/cnpg-plugin/' url to find the installation process for your distribution. The CloudNativePG PlugIn is required for the following tasks: Promoting, Restarting, Reloading, Setting Maintenance Modes, and Status
# To Deploy CloudNativePG Sandbox into Kubernetes Cluster
$ ansible-playbook manage_cnpg.yml BSD
Author:
- Doug Ortiz
- DevOps
- edb-devops@enterprisedb www.enterprisedb.com