Browse Source

Merge pull request #2942 from mtnbikenc/ansible-version

Minimum Ansible version check
Tim Bielawa 8 years ago
parent
commit
760ea5d197

+ 46 - 0
callback_plugins/0_version_requirement.py

@@ -0,0 +1,46 @@
+#!/usr/bin/python
+
+import sys
+from ansible import __version__
+
+if __version__ < '2.0':
+    from ansible.callbacks import display as pre2_display
+    CallbackBase = object
+
+    def display(*args, **kwargs):
+        pre2_display(*args, **kwargs)
+else:
+    from ansible.plugins.callback import CallbackBase
+    from ansible.utils.display import Display
+
+    def display(*args, **kwargs):
+        display_instance = Display()
+        display_instance.display(*args, **kwargs)
+
+
+# Set to minimum required Ansible version
+required_version = '2.2.0.0'
+DESCRIPTION = "Supported versions: %s or newer" % required_version
+
+
+def version_requirement(version):
+    return version >= required_version
+
+
+class CallbackModule(CallbackBase):
+    """
+    This callback module stops playbook execution if the Ansible
+    version is less than required, defined by required_version
+    """
+
+    CALLBACK_VERSION = 1.0
+    CALLBACK_NAME = 'version_requirement'
+
+    def __init__(self):
+        super(CallbackModule, self).__init__()
+
+        if not version_requirement(__version__):
+            display(
+                'FATAL: Current Ansible version (%s) is not supported. %s'
+                % (__version__, DESCRIPTION), color='red')
+            sys.exit(1)

+ 0 - 2
playbooks/aws/openshift-cluster/config.yml

@@ -1,6 +1,4 @@
 ---
-- include: ../../common/openshift-cluster/verify_ansible_version.yml
-
 - hosts: localhost
   gather_facts: no
   tasks:

+ 0 - 4
playbooks/byo/openshift-cluster/config.yml

@@ -1,8 +1,4 @@
 ---
-- include: ../../common/openshift-cluster/verify_ansible_version.yml
-  tags:
-  - always
-
 - name: Create initial host groups for localhost
   hosts: localhost
   connection: local

+ 1 - 3
playbooks/byo/openshift-cluster/enable_dnsmasq.yml

@@ -1,6 +1,4 @@
 ---
-- include: ../../common/openshift-cluster/verify_ansible_version.yml
-
 - hosts: localhost
   connection: local
   become: no
@@ -16,5 +14,5 @@
   gather_facts: no
   tasks:
   - include_vars: ../../byo/openshift-cluster/cluster_hosts.yml
-  
+
 - include: ../../common/openshift-cluster/enable_dnsmasq.yml

+ 1 - 3
playbooks/byo/openshift-cluster/redeploy-certificates.yml

@@ -1,6 +1,4 @@
 ---
-- include: ../../common/openshift-cluster/verify_ansible_version.yml
-
 - hosts: localhost
   connection: local
   become: no
@@ -16,7 +14,7 @@
   gather_facts: no
   tasks:
   - include_vars: ../../byo/openshift-cluster/cluster_hosts.yml
-  
+
 - include: ../../common/openshift-cluster/redeploy-certificates.yml
   vars:
     openshift_deployment_type: "{{ deployment_type }}"

+ 0 - 2
playbooks/byo/openshift-cluster/upgrades/upgrade_etcd.yml

@@ -1,6 +1,4 @@
 ---
-- include: ../../../common/openshift-cluster/verify_ansible_version.yml
-
 - name: Create initial host groups for localhost
   hosts: localhost
   connection: local

+ 0 - 2
playbooks/byo/openshift_facts.yml

@@ -1,6 +1,4 @@
 ---
-- include: ../common/openshift-cluster/verify_ansible_version.yml
-
 - hosts: localhost
   connection: local
   become: no

+ 0 - 2
playbooks/common/openshift-cluster/upgrades/init.yml

@@ -1,6 +1,4 @@
 ---
-- include: ../verify_ansible_version.yml
-
 - hosts: localhost
   connection: local
   become: no

+ 0 - 11
playbooks/common/openshift-cluster/verify_ansible_version.yml

@@ -1,11 +0,0 @@
----
-- name: Verify Ansible version is greater than or equal to 2.2.0
-  hosts: localhost
-  connection: local
-  become: no
-  gather_facts: no
-  tasks:
-  - name: Verify Ansible version is greater than or equal to 2.2.0
-    fail:
-      msg: "Unsupported ansible version: {{ ansible_version.full }} found"
-    when: not ansible_version.full | version_compare('2.2.0', 'ge')

+ 0 - 2
playbooks/libvirt/openshift-cluster/config.yml

@@ -3,8 +3,6 @@
 # is localhost, so no hostname value (or public_hostname) value is getting
 # assigned
 
-- include: ../../common/openshift-cluster/verify_ansible_version.yml
-
 - hosts: localhost
   gather_facts: no
   tasks:

+ 0 - 2
playbooks/openstack/openshift-cluster/config.yml

@@ -1,6 +1,4 @@
 ---
-- include: ../../common/openshift-cluster/verify_ansible_version.yml
-
 - hosts: localhost
   gather_facts: no
   tasks: