aa_version_requirement.py 2.6 KB

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