blob: 40affb18be888692593a0a48a6bcec3986b8f8f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#!/usr/bin/python
"""
This callback plugin verifies the required minimum version of Ansible
is installed for proper operation of the OpenShift Ansible Installer.
The plugin is named with leading `aa_` to ensure this plugin is loaded
first (alphanumerically) by Ansible.
"""
import sys
from ansible import __version__
if __version__ < '2.0':
# pylint: disable=import-error,no-name-in-module
# Disabled because pylint warns when Ansible v2 is installed
from ansible.callbacks import display as pre2_display
CallbackBase = object
def display(*args, **kwargs):
"""Set up display function for pre Ansible v2"""
pre2_display(*args, **kwargs)
else:
from ansible.plugins.callback import CallbackBase
from ansible.utils.display import Display
def display(*args, **kwargs):
"""Set up display function for Ansible v2"""
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 (except 2.2.1.0)" % REQUIRED_VERSION
FAIL_ON_2_2_1_0 = "There are known issues with Ansible version 2.2.1.0 which " \
"are impacting OpenShift-Ansible. Please use Ansible " \
"version 2.2.0.0 or a version greater than 2.2.1.0. " \
"See this issue for more details: " \
"https://github.com/openshift/openshift-ansible/issues/3111"
def version_requirement(version):
"""Test for minimum required version"""
return version >= REQUIRED_VERSION
class CallbackModule(CallbackBase):
"""
Ansible callback plugin
"""
CALLBACK_VERSION = 1.0
CALLBACK_NAME = 'version_requirement'
def __init__(self):
"""
Version verification is performed in __init__ to catch the
requirement early in the execution of Ansible and fail gracefully
"""
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)
if __version__ == '2.2.1.0':
display(
'FATAL: Current Ansible version (%s) is not supported. %s'
% (__version__, FAIL_ON_2_2_1_0), color='red')
sys.exit(1)
|