Verify offline app repo is working 91/82091/8
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Wed, 13 Mar 2019 08:33:53 +0000 (09:33 +0100)
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>
Wed, 3 Apr 2019 11:32:47 +0000 (13:32 +0200)
A patch for failing fast if configured offline
application repository is not working properly.
Just adding repo to repolist doesn't guarantee
it's really operational.

Change-Id: I65372b9b1ea5f5dcb797548b14e3ae1295668592
Issue-ID: OOM-1689
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
ansible/infrastructure.yml
ansible/roles/package-repository-check/tasks/RedHat.yml [new file with mode: 0644]
ansible/roles/package-repository-check/tasks/main.yml [new file with mode: 0644]

index 74a7b68..e49ee91 100644 (file)
@@ -3,12 +3,13 @@
   hosts: infrastructure, kubernetes
   roles:
     - package-repository
-    - role: firewall
+    - firewall
 
 - name: Setup infrastructure servers
   hosts: infrastructure
   roles:
     - chrony
+    - package-repository-check
     - certificates
     - docker
     - dns
@@ -20,6 +21,7 @@
   hosts: kubernetes
   roles:
     - chrony
+    - package-repository-check
     - docker
   tasks:
     - include_role:
diff --git a/ansible/roles/package-repository-check/tasks/RedHat.yml b/ansible/roles/package-repository-check/tasks/RedHat.yml
new file mode 100644 (file)
index 0000000..ed496f9
--- /dev/null
@@ -0,0 +1,20 @@
+---
+- name: verify
+  block:
+    # Clean cache prior to refreshing
+    - name: Clean yum cache
+      command: yum clean all
+      args:
+        warn: false
+    # Refresh cache to ensure repo is reachable
+    - name: Update yum cache
+      yum:
+        update_cache: yes
+        state: latest
+      tags:
+        - skip_ansible_lint # Prevent '[403] Package installs should not use latest' ansible lint task rule
+  rescue:
+    - name: Fail if yum cache updating failed
+      fail:
+        msg: "Couldn't refresh yum cache, repositories not configured properly. Check ansible logs for details."
+  become: true
diff --git a/ansible/roles/package-repository-check/tasks/main.yml b/ansible/roles/package-repository-check/tasks/main.yml
new file mode 100644 (file)
index 0000000..ac63ece
--- /dev/null
@@ -0,0 +1,12 @@
+---
+# Purpose of this role is to check whether configured repositories are working.
+#
+# Successfull prior invocation of 'package-repository' role on 'infrastructure' hosts
+# is prerequisite for playing this one on 'infrastructure' group.
+#
+# Successfull prior invocation of 'package-repository' and 'nginx' role on infrastructure hosts
+# is prerequisite for playing this one on 'kubernetes' group.
+
+#Set of tasks designated to failing fast if configured repos are not functioning properly
+- include_tasks: "{{ ansible_os_family }}.yml"
+  when: ansible_os_family == 'RedHat'