Explorar o código

add strategy playbooks

Grega Bremec hai 7 meses
pai
achega
88c20df950
Modificáronse 2 ficheiros con 83 adicións e 0 borrados
  1. 35 0
      playbooks/strategy-finish.yml
  2. 48 0
      playbooks/strategy-start.yml

+ 35 - 0
playbooks/strategy-finish.yml

@@ -0,0 +1,35 @@
+---
+- name: Clean up after the strategies exercise
+  hosts: workstation.lab.example.com
+  gather_subset: min
+  become: no
+  tasks:
+    - name: Make sure kubeconfig is there on utility
+      delegate_to: utility.lab.example.com
+      file:
+        path: /home/lab/{{ item }}/auth/kubeconfig
+        state: file
+      loop: "{{ clusters }}"
+
+    - name: Create a temp dir
+      file:
+        path: tmp
+        state: directory
+
+    - name: Copy over the kubeconfig
+      delegate_to: utility.lab.example.com
+      fetch:
+        src: /home/lab/{{ item }}/auth/kubeconfig
+        dest: tmp/kubeconfig-{{ item }}
+        flat: yes
+      loop: "{{ clusters }}"
+
+    - name: Ensure the namespace for the exercise is gone
+      k8s:
+        kubeconfig: tmp/kubeconfig-ocp4
+        validate_certs: no
+        api_version: v1
+        kind: namespace
+        name: deployments-strategy
+        state: absent
+...

+ 48 - 0
playbooks/strategy-start.yml

@@ -0,0 +1,48 @@
+---
+- name: Prepare for the strategies exercise
+  hosts: workstation.lab.example.com
+  gather_subset: min
+  become: no
+  tasks:
+    - name: Make sure kubeconfig is there on utility
+      delegate_to: utility.lab.example.com
+      file:
+        path: /home/lab/{{ item }}/auth/kubeconfig
+        state: file
+      loop: "{{ clusters }}"
+
+    - name: Create a temp dir
+      file:
+        path: tmp
+        state: directory
+
+    - name: Copy over the kubeconfig
+      delegate_to: utility.lab.example.com
+      fetch:
+        src: /home/lab/{{ item }}/auth/kubeconfig
+        dest: tmp/kubeconfig-{{ item }}
+        flat: yes
+      loop: "{{ clusters }}"
+
+    - name: Check whether the namespace is already there
+      k8s_info:
+        kubeconfig: tmp/kubeconfig-ocp4
+        validate_certs: no
+        api_version: v1
+        kind: namespace
+        name: deployments-strategy
+      register: ge_nsp
+
+    - name: Fail if the namespace exists
+      fail:
+        msg: "The exercise namespace already exists: deployments-strategy; please run strategy-finish.yml to clean up first and then re-run this playbook."
+      when: ge_nsp.resources | length > 0
+
+    - name: Ensure there is a namespace for the exercise
+      k8s:
+        kubeconfig: tmp/kubeconfig-ocp4
+        validate_certs: no
+        api_version: v1
+        kind: namespace
+        name: deployments-strategy
+