Check if pxc secret exists and if no, create
diff --git a/roles/percona_xtradb_cluster/tasks/main.yml b/roles/percona_xtradb_cluster/tasks/main.yml
index e854896..384b701 100644
--- a/roles/percona_xtradb_cluster/tasks/main.yml
+++ b/roles/percona_xtradb_cluster/tasks/main.yml
@@ -1,22 +1,34 @@
- name: Create a secret for Percona XtraDB cluster passwords
run_once: true
- kubernetes.core.k8s:
- state: present
- definition:
- apiVersion: v1
- stringData:
- clustercheck: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
- monitor: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
- operator: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
- proxyadmin: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
- replication: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
- root: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
- xtrabackup: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
- kind: Secret
- metadata:
+ block:
+ - name: Check if the Percona XtraDB cluster secret exists
+ kubernetes.core.k8s_info:
+ api_version: v1
+ kind: Secret
name: percona-xtradb
namespace: openstack
- type: Opaque
+ register: _pxc_secret
+ ignore_errors: true
+
+ - name: Create a secret
+ when: ( _pxc_secret.resources | length==0 )
+ kubernetes.core.k8s:
+ state: present
+ definition:
+ apiVersion: v1
+ stringData:
+ clustercheck: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
+ monitor: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
+ operator: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
+ proxyadmin: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
+ replication: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
+ root: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
+ xtrabackup: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=32') }}"
+ kind: Secret
+ metadata:
+ name: percona-xtradb
+ namespace: openstack
+ type: Opaque
- name: Create Percona XtraDB cluster
run_once: true