Преглед изворни кода

add inventory, check role, and the (more or less) standard pre-flight playbook

Grega Bremec пре 4 месеци
родитељ
комит
7d2fdaeb22
5 измењених фајлова са 121 додато и 0 уклоњено
  1. 3 0
      check-env/defaults/main.yml
  2. 72 0
      check-env/tasks/main.yml
  3. 8 0
      check-env/vars/main.yml
  4. 27 0
      inventory.yml
  5. 11 0
      pre-flight.yml

+ 3 - 0
check-env/defaults/main.yml

@@ -0,0 +1,3 @@
+---
+# ???
+...

+ 72 - 0
check-env/tasks/main.yml

@@ -0,0 +1,72 @@
+---
+# Variables affecting this role:
+#
+#  tools:
+#    - final_name: the path to the tool to check for
+#      completion: look for bash_completion or no
+#      completion_file: the name of the bash completion file
+#  clusters:
+#   just a simple list of clusters to check
+#
+- 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
+
+# XXX This won't do if you install it using pip.
+- name: We also need python38-jmespath
+  become: yes
+  package:
+    name: python38-jmespath
+    state: latest
+
+- name: We need some additional collections as well.
+  become: yes
+  yum:
+    name:
+      - ansible-core
+      - ansible-collection-ansible-posix
+      - ansible-collection-ansible-utils
+      - ansible-collection-community-general
+      - ansible-collection-containers-podman
+    state: latest
+
+- name: Verify cluster connectivity
+  kubernetes.core.k8s_cluster_info:
+    kubeconfig: tmp/kubeconfig-{{ item }}
+    validate_certs: no
+  loop: "{{ clusters }}"
+...

+ 8 - 0
check-env/vars/main.yml

@@ -0,0 +1,8 @@
+---
+# need the following variables somewhere in global vars collection:
+# 
+#  - tools
+#  - clusters
+#
+# consult the role tasks file for an explanation
+...

+ 27 - 0
inventory.yml

@@ -0,0 +1,27 @@
+---
+# A simplistic inventory for the classroom VMs.
+all:
+  hosts:
+    workstation.lab.example.com:
+      ansible_connection: local
+    utility.lab.example.com:
+      ansible_user: lab
+    bastion.lab.example.com:
+      ansible_user: root
+
+  vars:
+    # OpenShift versions.
+    ocp_maj: "4.14"
+    ocp_z: "4.14.12"
+
+    # These are the tools we need, some also need to be downloaded.
+    tools:
+      oc:
+        final_name: /usr/bin/oc
+        completion: yes
+        completion_file: oc
+
+    # The list of OpenShift clusters check-env will try to connect to.
+    clusters:
+      - ocp4
+...

+ 11 - 0
pre-flight.yml

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