Bladeren bron

basic pre-flight check

Grega Bremec 2 jaren geleden
commit
b039e83723
6 gewijzigde bestanden met toevoegingen van 99 en 0 verwijderingen
  1. 6 0
      .gitignore
  2. 11 0
      ansible.cfg
  3. 9 0
      inventory
  4. 9 0
      pre-flight.yml
  5. 55 0
      roles/check-env/tasks/main.yml
  6. 9 0
      roles/check-env/vars/main.yml

+ 6 - 0
.gitignore

@@ -0,0 +1,6 @@
+.DS_Store
+.*.sw?
+*.vim
+kubeconfig*
+kubeadmin*
+tmp*

+ 11 - 0
ansible.cfg

@@ -0,0 +1,11 @@
+[defaults]
+# required to evade implicit conversion to string in k8s resource_definition
+jinja2_native = True
+inventory = ./inventory
+remote_user = student
+ask_pass = no
+
+[privilege_escalation]
+become = no
+become_method = sudo
+become_askpass = no

+ 9 - 0
inventory

@@ -0,0 +1,9 @@
+workstation.lab.example.com ansible_connection=local
+utility.lab.example.com ansible_user=lab
+bastion.lab.example.com ansible_user=root
+
+# Example: override variables here.
+[all:vars]
+ocp_maj = "4.10"
+ocp_z = "4.10.3"
+

+ 9 - 0
pre-flight.yml

@@ -0,0 +1,9 @@
+---
+- name: Pre-flight checks only.
+  hosts: workstation.lab.example.com
+  gather_subset: min
+  become: no
+  roles:
+    - role: check-env
+      tags: check
+...

+ 55 - 0
roles/check-env/tasks/main.yml

@@ -0,0 +1,55 @@
+---
+# Variables affecting this role:
+#
+#  tools:
+#    - final_name: the name of the tool to check for
+#      completion: look for bash_completion or no
+#  clusters:
+#   just a simple list of clusters to check
+#
+# TODO: move clusters somewhere else than vars/ and perhaps make it richer
+#
+- name: Check for tools
+  file:
+    path: "{{ tools[item].final_name }}"
+    state: file
+  loop: "{{ tools.keys() | list }}"
+
+- name: Check for completion files
+  file:
+    path: /etc/bash_completion.d/{{ tools[item].completion_file }}
+    state: file
+  when: tools[item].completion
+  loop: "{{ tools.keys() | list }}"
+
+- 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: "We need python-kubernetes >= 12"
+  become: yes
+  pip:
+    name: kubernetes>=12.0.0
+
+- name: Verify cluster connectivity
+  kubernetes.core.k8s_cluster_info:
+    kubeconfig: tmp/kubeconfig-{{ item }}
+    validate_certs: no
+  loop: "{{ clusters }}"
+...

+ 9 - 0
roles/check-env/vars/main.yml

@@ -0,0 +1,9 @@
+---
+tools:
+  oc:
+    final_name: /usr/bin/oc
+    completion_file: oc
+    completion: yes
+clusters:
+  - ocp4
+...