]> git.apps.os.sepia.ceph.com Git - ceph-cm-ansible.git/commitdiff
Adding jenkins ocp4 jobs restore playbook 644/head
authorAdam Kraitman <akraitma@redhat.com>
Tue, 17 Aug 2021 15:31:02 +0000 (18:31 +0300)
committerAdam Kraitman <akraitma@redhat.com>
Wed, 18 Aug 2021 11:40:20 +0000 (14:40 +0300)
Signed-off-by: Adam Kraitman <akraitma@redhat.com>
tools/downstream-jenkins-sync-jobs.yml [new file with mode: 0644]

diff --git a/tools/downstream-jenkins-sync-jobs.yml b/tools/downstream-jenkins-sync-jobs.yml
new file mode 100644 (file)
index 0000000..123e2b6
--- /dev/null
@@ -0,0 +1,51 @@
+---
+# This playbook is used to sync the jenkins jobs from one ocp pod folder to another pod folder
+# Usage:
+# ansible-playbook downstream-jenkins-sync-jobs.yml --extra-vars "src_pod=gluster-downstream-jenkins src_folder=/var/lib/jenkins/restore/jobs/ dest_pod=gluster-new-jenkins dest_folder=/var/lib/jenkins/jobs/"
+# Varibles:
+# src_pod - The pod name that holds the jobs that will get copied to the destination pod
+# src_folder - The folder on the src_pod that includs the jobs the will be copied to the dest_pod
+# dest_pod - The pod name that the jobs will get copied to
+# dest_folder - The folder on the dest_pod where the jobs the will be copied to
+# 
+- hosts: localhost
+  gather_facts: false
+  tasks:
+
+  - name: Check oc tool installation status
+    command: which oc
+    changed_when: false
+    failed_when: false
+    register: oc_installed
+
+  - name: Fail if oc tool is not installed
+    fail:
+      msg: "oc tool appears to be missing, install first and connect with your user to the ocp cluster by running oc login"
+    when: oc_installed is failed
+
+  - name: Check connected oc client user
+    command: oc whoami
+    ignore_errors: True
+    register: oc_whoami
+
+  - name: Fail if oc user is not connected
+    fail:
+      msg: "Please login to the ocp cluster by running oc login"
+    when: oc_whoami.rc != 0
+
+  - name: Create temporary directory
+    tempfile:
+      state: directory
+    register: tmpdir
+
+  - name: rsync jobs from source pod to local folder
+    shell: oc rsync $(oc get pods | grep -i Running | grep -i "{{ src_pod }}" | awk '{ print $1 }'):"{{ src_folder }}" "{{ tmpdir.path }}"
+
+  - name: rsync jobs from local folder to destination pod
+    shell: oc rsync "{{ tmpdir.path }}" $(oc get pods | grep -i Running | grep -i "{{ dest_pod }}" | awk '{ print $1 }'):"{{ dest_folder }}"
+
+  - name: Remove the temporary directory
+    file:
+      path: "{{ tmpdir.path }}"
+      state: absent
+    when: tmpdir.path is defined