From 04863be9e593b48f4add1424fef309ffed6cba64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kone=C4=8Dn=C3=BD?= Date: Wed, 15 Jul 2020 17:10:16 +0200 Subject: [PATCH] Add SAR script support for Openshift apps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Konečný --- inventory/group_vars/os_masters | 13 +++++++++++++ playbooks/manual/gdpr/sar.yml | 6 ++++++ playbooks/manual/gdpr/sar_openshift.yml | 15 +++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 playbooks/manual/gdpr/sar_openshift.yml diff --git a/inventory/group_vars/os_masters b/inventory/group_vars/os_masters index 3920863845..ccc5ef87b1 100644 --- a/inventory/group_vars/os_masters +++ b/inventory/group_vars/os_masters @@ -14,3 +14,16 @@ nagios_Check_Services: # bodhi_version: 5.4.1 bodhi_openshift_pods: 2 + +# GDPR SAR related dictionary +sar_openshift: + # Name of the app + release-monitoring: + # Location of the script + sar_script: /usr/local/bin/sar.py + # Output file on local machine + sar_output_file: anitya.json + # Openshift namespace where the app runs + openshift_namespace: release-monitoring + # Name of openshift pod - will be used for label search + openshift_pod: release-monitoring-web diff --git a/playbooks/manual/gdpr/sar.yml b/playbooks/manual/gdpr/sar.yml index 5da97c5358..e67712d0d4 100644 --- a/playbooks/manual/gdpr/sar.yml +++ b/playbooks/manual/gdpr/sar.yml @@ -44,6 +44,12 @@ delegate_to: localhost when: "sar_huge is defined and sar_huge" +- name: Gather SAR data - openshift apps + hosts: os_masters[0] + tasks: + - include_tasks: sar_openshift.yml + loop: "{{ lookup('dict', sar_openshift, wantlist=True) }}" + - name: Create the archive hosts: localhost tasks: diff --git a/playbooks/manual/gdpr/sar_openshift.yml b/playbooks/manual/gdpr/sar_openshift.yml new file mode 100644 index 0000000000..94b4319c95 --- /dev/null +++ b/playbooks/manual/gdpr/sar_openshift.yml @@ -0,0 +1,15 @@ +# Retrieve GDPR data from single openshift app. +# Get the correct pod +- name: Retrieve the id of the running container/pod + shell: "oc get -n {{ item.value.openshift_namespace }} -o name -l app={{ item.value.openshift_pod }} pods | cut -f 2 -d '/'" + register: pod_id +# Run the SAR script +- name: Run oc exec in container to extract the data + command: "oc -n {{ item.value.openshift_namespace }} rsh {{ pod_id.stdout }} bash -c 'SAR_USERNAME={{ sar_fas_user }} SAR_EMAIL={{ sar_email }} {{ item.value.sar_script }}'" + register: sar_data +# Store the result on disk +- name: Copy the output data locally + copy: + content: "{{ sar_data['stdout'] }}" + dest: "{{ hostvars['localhost']['sar_tmp_dir'] }}/{{ item.value.sar_output_file }}" + delegate_to: localhost