Forráskód Böngészése

add a role to (re)install lab scripts

Grega Bremec 3 hete
szülő
commit
9735d34eb7

+ 6 - 0
playbooks/pre-flight.yml

@@ -19,4 +19,10 @@
     - include_role:
         name: deploy-operator
       tags: prep
+    - include_role:
+        name: install-labs
+      tags: workstation
+    - include_role:
+        name: prep-workspace
+      tags: workstation
 ...

+ 8 - 0
playbooks/roles/install-labs/defaults/main.yml

@@ -0,0 +1,8 @@
+---
+# Defaults for the install-labs role.
+
+lab_sku: ad482
+lab_package: "rht-labs-{{ lab_sku }}"
+lab_index_url: https://pypi.apps.tools-na.prod.nextcle.com/repository/labs/simple/
+lab_files_fixes: []
+...

+ 44 - 0
playbooks/roles/install-labs/tasks/main.yml

@@ -0,0 +1,44 @@
+---
+# Updates pip, installs the lab scripts.
+#
+# The following variables must exist:
+#
+#   lab_sku:            ad482 (or some other SKU)
+#   lab_package:        rht-labs-{{ lab_sku }}
+#   lab_index_url:      https://pypi.apps.tools-na.prod.nextcle.com/repository/labs/simple/
+#   lab_files_fixes:    a list of patch files to apply to lab materials
+#
+- name: Upgrade pip
+  ansible.builtin.pip:
+    name: pip
+    state: latest
+
+- name: Install the lab package
+  ansible.builtin.pip:
+    name: "{{ lab_package }}"
+    state: present
+    extra_args: "--extra-index-url {{ lab_index_url }}"
+
+- name: Set the grading_config_file fact for convenience
+  set_fact:
+    grading_config_file: "{{ ansible_facts['user_dir'] }}/.grading/config.yaml"
+
+- name: Check if the grading config is there
+  ansible.builtin.stat:
+    path: "{{ grading_config_file }}"
+  register: grading_file
+
+- name: Load the current grading config
+  set_fact:
+    grading_cfg: "{{ lookup('ansible.builtin.file', grading_config_file) | from_yaml }}"
+  when: grading_file.stat.exists
+
+- name: Extract the current SKU
+  set_fact:
+    current_sku: "{{ grading_cfg.rhtlab.course.sku }}"
+  when: grading_cfg is defined
+
+- name: Activate the new labs
+  ansible.builtin.shell: "lab select {{ lab_sku }}"
+  when: (current_sku is not defined) or (current_sku != lab_sku)
+...