Browse Source

Refactor preflight check into roles

Rodolfo Carvalho 8 years ago
parent
commit
9041a81621

+ 0 - 3
ansible.cfg.example

@@ -13,9 +13,6 @@ roles_path = roles/
 # Set the log_path
 log_path = /tmp/ansible.log
 
-# prints a descriptive summary of failed tasks
-callback_plugins = ./callback_plugins
-
 # Uncomment to use the provided BYO inventory
 #hostfile = inventory/byo/hosts
 

+ 1 - 9
playbooks/adhoc/preflight/README.md

@@ -36,15 +36,7 @@ against your inventory file. Here is the step-by-step:
     $ cd openshift-ansible
     ```
 
-2. Configure a custom callback plugin to get a summary of problems at the end of
-the playbook run:
-
-    ```console
-    $ export ANSIBLE_CALLBACK_PLUGINS=callback_plugins \
-             ANSIBLE_STDOUT_CALLBACK=default_plus_summary
-    ```
-
-3. Run the playbook:
+2. Run the playbook:
 
     ```console
     $ ansible-playbook -i <inventory file> playbooks/adhoc/preflight/check.yml

+ 13 - 140
playbooks/adhoc/preflight/check.yml

@@ -1,159 +1,32 @@
 ---
 - hosts: OSEv3
   gather_facts: no
-  tasks:
-    - set_fact:
-        deployment_type: "{{ deployment_type | default('openshift-enterprise') }}"
-        containerized: "{{ containerized | default('no') | bool }}"
-        openshift_release: "{{ openshift_release | default('3.3') }}"
-        oo_preflight_check_results: "{{ oo_preflight_check_results | default([]) }}"
+  roles:
+    - openshift_preflight/facts
 
 - hosts: OSEv3
-  name: check content available on all hosts
+  name: checks that apply to all hosts
   gather_facts: no
   ignore_errors: yes
-  tasks:
-    - when:
-        - not containerized
-      block:
-
-        - name: determine if yum update will work
-          action: check_yum_update
-          register: r
-
-        - set_fact:
-            oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'check content available on all hosts'})] }}"
-
-        - name: determine if expected version matches what is available
-          aos_version:
-            version: "{{ openshift_release }}"
-          when:
-            - deployment_type == "openshift-enterprise"
-          register: r
-
-        - set_fact:
-            oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'determine if expected version matches what is available'})] }}"
+  roles:
+    - openshift_preflight/common
 
 - hosts: masters
-  name: determine if yum install of master pkgs will work
+  name: checks that apply to masters
   gather_facts: no
   ignore_errors: yes
-  tasks:
-    - when:
-        - not containerized
-      block:
-
-        - name: main packages for enterprise
-          when:
-            - deployment_type == "openshift-enterprise"
-          check_yum_update:
-            packages:
-              - atomic-openshift
-              - atomic-openshift-clients
-              - atomic-openshift-master
-          register: r
-
-        - set_fact:
-            oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'main packages for enterprise'})] }}"
-
-        - name: main packages for origin
-          when:
-            - deployment_type == "origin"
-          check_yum_update:
-            packages:
-              - origin
-              - origin-clients
-              - origin-master
-          register: r
-
-        - set_fact:
-            oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'main packages for origin'})] }}"
-
-        - name: other master packages
-          check_yum_update:
-            packages:
-              - etcd
-              - bash-completion
-              - cockpit-bridge
-              - cockpit-docker
-              - cockpit-kubernetes
-              - cockpit-shell
-              - cockpit-ws
-              - httpd-tools
-          register: r
-
-        - set_fact:
-            oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'other master packages'})] }}"
+  roles:
+    - openshift_preflight/masters
 
 - hosts: nodes
-  name: determine if yum install of node pkgs will work
+  name: checks that apply to nodes
   gather_facts: no
   ignore_errors: yes
-  tasks:
-    - when:
-        - not containerized
-      block:
-
-        - name: main packages for enterprise
-          when:
-            - deployment_type == "openshift-enterprise"
-          check_yum_update:
-            packages:
-              - atomic-openshift
-              - atomic-openshift-node
-              - atomic-openshift-sdn-ovs
-          register: r
-
-        - set_fact:
-            oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'main packages for enterprise'})] }}"
-
-        - name: main packages for origin
-          when:
-            - deployment_type == "origin"
-          check_yum_update:
-            packages:
-              - origin
-              - origin-node
-              - origin-sdn-ovs
-          register: r
-
-        - set_fact:
-            oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'main packages for origin'})] }}"
-
-        - name: other node packages
-          check_yum_update:
-            packages:
-              - docker
-              - PyYAML
-              - firewalld
-              - iptables
-              - iptables-services
-              - nfs-utils
-              - ntp
-              - yum-utils
-              - dnsmasq
-              - libselinux-python
-              - ceph-common
-              - glusterfs-fuse
-              - iscsi-initiator-utils
-              - pyparted
-              - python-httplib2
-              - openssl
-              - flannel
-              - bind
-          register: r
-
-        - set_fact:
-            oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'other node packages'})] }}"
+  roles:
+    - openshift_preflight/nodes
 
 - hosts: OSEv3
   name: verify check results
   gather_facts: no
-  tasks:
-
-    - set_fact:
-        oo_preflight_check_failures: "{{ oo_preflight_check_results | select('failed', 'equalto', True) | list }}"
-
-    - name: ensure all checks succeed
-      action: fail
-      when: oo_preflight_check_failures
+  roles:
+    - openshift_preflight/verify_status

+ 53 - 0
roles/openshift_preflight/README.md

@@ -0,0 +1,53 @@
+OpenShift Preflight Checks
+==========================
+
+This role detects common problems prior to installing OpenShift.
+
+Requirements
+------------
+
+* Ansible 2.2+
+
+Role Variables
+--------------
+
+None
+
+Dependencies
+------------
+
+None
+
+Example Playbook
+----------------
+
+```yaml
+---
+- hosts: OSEv3
+  gather_facts: no
+  roles:
+    - openshift_preflight/facts
+
+- hosts: OSEv3
+  name: checks that apply to all hosts
+  gather_facts: no
+  ignore_errors: yes
+  roles:
+    - openshift_preflight/common
+
+- hosts: OSEv3
+  name: verify check results
+  gather_facts: no
+  roles:
+    - openshift_preflight/verify_status
+```
+
+License
+-------
+
+Apache License Version 2.0
+
+Author Information
+------------------
+
+Customer Success team (dev@lists.openshift.redhat.com)

playbooks/adhoc/preflight/library → roles/openshift_preflight/common/library


+ 22 - 0
roles/openshift_preflight/common/tasks/main.yml

@@ -0,0 +1,22 @@
+---
+# check content available on all hosts
+- when:
+    - not containerized
+  block:
+
+    - name: determine if yum update will work
+      action: check_yum_update
+      register: r
+
+    - set_fact:
+        oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'check content available on all hosts'})] }}"
+
+    - name: determine if expected version matches what is available
+      aos_version:
+        version: "{{ openshift_release }}"
+      when:
+        - deployment_type == "openshift-enterprise"
+      register: r
+
+    - set_fact:
+        oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'determine if expected version matches what is available'})] }}"

+ 7 - 0
roles/openshift_preflight/facts/tasks/main.yml

@@ -0,0 +1,7 @@
+---
+- name: set common variables
+  set_fact:
+    deployment_type: "{{ deployment_type | default('openshift-enterprise') }}"
+    containerized: "{{ containerized | default('no') | bool }}"
+    openshift_release: "{{ openshift_release | default('3.3') }}"
+    oo_preflight_check_results: "{{ oo_preflight_check_results | default([]) }}"

+ 1 - 0
roles/openshift_preflight/masters/library

@@ -0,0 +1 @@
+../../../library

+ 47 - 0
roles/openshift_preflight/masters/tasks/main.yml

@@ -0,0 +1,47 @@
+---
+# determine if yum install of master pkgs will work
+- when:
+    - not containerized
+  block:
+
+    - name: main packages for enterprise
+      when:
+        - deployment_type == "openshift-enterprise"
+      check_yum_update:
+        packages:
+          - atomic-openshift
+          - atomic-openshift-clients
+          - atomic-openshift-master
+      register: r
+
+    - set_fact:
+        oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'main packages for enterprise'})] }}"
+
+    - name: main packages for origin
+      when:
+        - deployment_type == "origin"
+      check_yum_update:
+        packages:
+          - origin
+          - origin-clients
+          - origin-master
+      register: r
+
+    - set_fact:
+        oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'main packages for origin'})] }}"
+
+    - name: other master packages
+      check_yum_update:
+        packages:
+          - etcd
+          - bash-completion
+          - cockpit-bridge
+          - cockpit-docker
+          - cockpit-kubernetes
+          - cockpit-shell
+          - cockpit-ws
+          - httpd-tools
+      register: r
+
+    - set_fact:
+        oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'other master packages'})] }}"

+ 1 - 0
roles/openshift_preflight/nodes/library

@@ -0,0 +1 @@
+../../../library

+ 57 - 0
roles/openshift_preflight/nodes/tasks/main.yml

@@ -0,0 +1,57 @@
+---
+# determine if yum install of node pkgs will work
+- when:
+    - not containerized
+  block:
+
+    - name: main packages for enterprise
+      when:
+        - deployment_type == "openshift-enterprise"
+      check_yum_update:
+        packages:
+          - atomic-openshift
+          - atomic-openshift-node
+          - atomic-openshift-sdn-ovs
+      register: r
+
+    - set_fact:
+        oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'main packages for enterprise'})] }}"
+
+    - name: main packages for origin
+      when:
+        - deployment_type == "origin"
+      check_yum_update:
+        packages:
+          - origin
+          - origin-node
+          - origin-sdn-ovs
+      register: r
+
+    - set_fact:
+        oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'main packages for origin'})] }}"
+
+    - name: other node packages
+      check_yum_update:
+        packages:
+          - docker
+          - PyYAML
+          - firewalld
+          - iptables
+          - iptables-services
+          - nfs-utils
+          - ntp
+          - yum-utils
+          - dnsmasq
+          - libselinux-python
+          - ceph-common
+          - glusterfs-fuse
+          - iscsi-initiator-utils
+          - pyparted
+          - python-httplib2
+          - openssl
+          - flannel
+          - bind
+      register: r
+
+    - set_fact:
+        oo_preflight_check_results: "{{ oo_preflight_check_results + [r|combine({'_task': 'other node packages'})] }}"

+ 2 - 0
callback_plugins/failure_summary.py

@@ -11,6 +11,8 @@ from ansible.utils.color import stringc
 class CallbackModule(CallbackBase):
     '''
     This callback plugin stores task results and summarizes failures.
+    The file name is prefixed with `zz_` to make this plugin be loaded last by
+    Ansible, thus making its output the last thing that users see.
     '''
 
     CALLBACK_VERSION = 2.0

+ 8 - 0
roles/openshift_preflight/verify_status/tasks/main.yml

@@ -0,0 +1,8 @@
+---
+- name: find check failures
+  set_fact:
+    oo_preflight_check_failures: "{{ oo_preflight_check_results | select('failed', 'equalto', True) | list }}"
+
+- name: ensure all checks succeed
+  action: fail
+  when: oo_preflight_check_failures