aa_version_requirement.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 pkg_resources import parse_version
  10. from ansible import __version__
  11. from ansible.plugins.callback import CallbackBase
  12. from ansible.utils.display import Display
  13. def display(*args, **kwargs):
  14. """Set up display function for Ansible v2"""
  15. display_instance = Display()
  16. display_instance.display(*args, **kwargs)
  17. # Set to minimum required Ansible version
  18. REQUIRED_VERSION = '2.9.5'
  19. DESCRIPTION = "Supported versions: %s or newer" % REQUIRED_VERSION
  20. class CallbackModule(CallbackBase):
  21. """
  22. Ansible callback plugin
  23. """
  24. CALLBACK_VERSION = 1.0
  25. CALLBACK_NAME = 'version_requirement'
  26. def __init__(self):
  27. """
  28. Version verification is performed in __init__ to catch the
  29. requirement early in the execution of Ansible and fail gracefully
  30. """
  31. super(CallbackModule, self).__init__()
  32. if not parse_version(__version__) >= parse_version(REQUIRED_VERSION):
  33. display(
  34. 'FATAL: Current Ansible version (%s) is not supported. %s'
  35. % (__version__, DESCRIPTION), color='red')
  36. sys.exit(1)