set_version_facts.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. Ansible action plugin to set version facts
  3. """
  4. # pylint: disable=no-name-in-module, import-error, wrong-import-order
  5. from distutils.version import LooseVersion
  6. from ansible.plugins.action import ActionBase
  7. # pylint: disable=too-many-statements
  8. def set_version_facts_if_unset(version):
  9. """ Set version facts. This currently includes common.version and
  10. common.version_gte_3_x
  11. Args:
  12. version (string): version of openshift installed/to install
  13. Returns:
  14. dict: the facts dict updated with version facts.
  15. """
  16. facts = {}
  17. if version and version != "latest":
  18. version = LooseVersion(version)
  19. version_gte_3_10 = version >= LooseVersion('3.10')
  20. version_gte_3_11 = version >= LooseVersion('3.11')
  21. else:
  22. # 'Latest' version is set to True, 'Next' versions set to False
  23. version_gte_3_10 = True
  24. version_gte_3_11 = False
  25. facts['openshift_version_gte_3_10'] = version_gte_3_10
  26. facts['openshift_version_gte_3_11'] = version_gte_3_11
  27. if version_gte_3_11:
  28. examples_content_version = 'v3.11'
  29. else:
  30. examples_content_version = 'v3.10'
  31. facts['openshift_examples_content_version'] = examples_content_version
  32. return facts
  33. # pylint: disable=too-few-public-methods
  34. class ActionModule(ActionBase):
  35. """Action plugin to set version facts"""
  36. def run(self, tmp=None, task_vars=None):
  37. """Run set_version_facts"""
  38. result = super(ActionModule, self).run(tmp, task_vars)
  39. # Ignore settting self.task_vars outside of init.
  40. # pylint: disable=W0201
  41. self.task_vars = task_vars or {}
  42. result["changed"] = False
  43. result["failed"] = False
  44. result["msg"] = "Version facts set"
  45. version = self._task.args.get('version')
  46. result["ansible_facts"] = set_version_facts_if_unset(version)
  47. return result