Browse Source

Add playbook for running arbitrary health checks

This is useful on its own, and also aids in developing/testing new
checks that are not part of any playbook.

Since the intent when running this playbook is to execute checks, opt
for a less verbose explanation on the error summary.
Rodolfo Carvalho 7 years ago
parent
commit
f98c978bd4

+ 31 - 0
playbooks/byo/openshift-checks/README.md

@@ -26,6 +26,9 @@ callback plugin summarizes execution errors at the end of a playbook run.
 3. Certificate expiry playbooks ([certificate_expiry](certificate_expiry)) -
 3. Certificate expiry playbooks ([certificate_expiry](certificate_expiry)) -
    check that certificates in use are valid and not expiring soon.
    check that certificates in use are valid and not expiring soon.
 
 
+4. Adhoc playbook ([adhoc.yml](adhoc.yml)) - use it to run adhoc checks.
+   See the [next section](#the-adhoc-playbook) for a usage example.
+
 ## Running
 ## Running
 
 
 With a [recent installation of Ansible](../../../README.md#setup), run the playbook
 With a [recent installation of Ansible](../../../README.md#setup), run the playbook
@@ -58,6 +61,34 @@ against your inventory file. Here is the step-by-step:
     $ ansible-playbook -i <inventory file> playbooks/byo/openshift-checks/certificate_expiry/default.yaml -v
     $ ansible-playbook -i <inventory file> playbooks/byo/openshift-checks/certificate_expiry/default.yaml -v
     ```
     ```
 
 
+### The adhoc playbook
+
+The adhoc playbook gives flexibility to run any check or a custom group of
+checks. What will be run is determined by the `openshift_checks` variable,
+which, among other ways supported by Ansible, can be set on the command line
+using the `-e` flag.
+
+For example, to run the `docker_storage` check:
+
+```console
+$ ansible-playbook -i <inventory file> playbooks/byo/openshift-checks/adhoc.yml -e openshift_checks=docker_storage
+```
+
+To run more checks, use a comma-separated list of check names:
+
+```console
+$ ansible-playbook -i <inventory file> playbooks/byo/openshift-checks/adhoc.yml -e openshift_checks=docker_storage,disk_availability
+```
+
+To run an entire class of checks, use the name of a check group tag, prefixed by `@`. This will run all checks tagged `preflight`:
+
+```console
+$ ansible-playbook -i <inventory file> playbooks/byo/openshift-checks/adhoc.yml -e openshift_checks=@preflight
+```
+
+It is valid to specify multiple check tags and individual check names together
+in a comma-separated list.
+
 ## Running in a container
 ## Running in a container
 
 
 This repository is built into a Docker image including Ansible so that it can
 This repository is built into a Docker image including Ansible so that it can

+ 6 - 0
playbooks/byo/openshift-checks/adhoc.yml

@@ -0,0 +1,6 @@
+---
+- include: ../openshift-cluster/initialize_groups.yml
+
+- include: ../../common/openshift-cluster/std_include.yml
+
+- include: ../../common/openshift-checks/adhoc.yml

+ 12 - 0
playbooks/common/openshift-checks/adhoc.yml

@@ -0,0 +1,12 @@
+---
+- name: OpenShift health checks
+  hosts: oo_all_hosts
+  roles:
+  - openshift_health_checker
+  vars:
+  - r_openshift_health_checker_playbook_context: adhoc
+  post_tasks:
+  - name: Run health checks
+    action: openshift_health_check
+    args:
+      checks: '{{ openshift_checks | default([]) }}'

+ 1 - 1
roles/openshift_health_checker/callback_plugins/zz_failure_summary.py

@@ -101,7 +101,7 @@ class CallbackModule(CallbackBase):
             'Variables can be set in the inventory or passed on the\n'
             'Variables can be set in the inventory or passed on the\n'
             'command line using the -e flag to ansible-playbook.\n\n'
             'command line using the -e flag to ansible-playbook.\n\n'
         ).format(playbook=self._playbook_file, checks=checks)
         ).format(playbook=self._playbook_file, checks=checks)
-        if context in ['pre-install', 'health']:
+        if context in ['pre-install', 'health', 'adhoc']:
             summary = (  # user was expecting to run checks, less explanation needed
             summary = (  # user was expecting to run checks, less explanation needed
                 '\n'
                 '\n'
                 'You may choose to configure or disable failing checks by\n'
                 'You may choose to configure or disable failing checks by\n'