This repository was archived by the owner on Jun 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathpackage.py
More file actions
64 lines (48 loc) · 2.79 KB
/
package.py
File metadata and controls
64 lines (48 loc) · 2.79 KB
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
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2021 Intel Corporation
""" package module wrapper for handling python3 support on CentOS 7.x and RHEL 7.x.
To enable usage of python3 interpreter globaly we need to fall back to python2 for yum module,
which is not available for python3
Additional task_vars:
ansible_python_interpreter -- set to /usr/bin/python if ansible_os_family is Redhat
and os version is less than 8
"""
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type # pylint: disable=invalid-name
from ansible.plugins.action import ActionBase
from ansible.utils.display import Display
display = Display() # pylint: disable=invalid-name
class ActionModule(ActionBase):
"""package action plugin wrapper handling python3 support on CentOS 7.x and RHEL 7.x"""
def run(self, tmp=None, task_vars=None):
'''
Action plugin wrapper for package action plugin.
Prepares support for python3 on CentOS 7.x and RHEL 7.x, where ansible yum module
is not available.
Since the Ansible module for yum call python APIs natively on the
backend, we need to handle this here and execute on the remote system.
'''
print(" package action plugin wrapper was called")
del tmp # tmp no longer has any effect
# Add/Change ansible_python_interpreter to python2 for CentOS 7.x and RHEL 7.x
# pylint: disable=f-string-without-interpolation
is_redhat_family_7 = \
self._templar.template("{{ (ansible_os_family == 'RedHat' and ansible_distribution != 'openEuler' and "
"ansible_distribution_version < '8') | bool }}")
if is_redhat_family_7:
if 'ansible_python_interpreter' in task_vars:
display.vv(f"Original ansible_python_interpreter: "
f"{task_vars['ansible_python_interpreter']}")
task_vars['ansible_python_interpreter'] = "/usr/bin/python"
display.vv(f"Updated ansible_python_interpreter: "
f"{task_vars['ansible_python_interpreter']}")
command_action = \
self._shared_loader_obj.action_loader.get('ansible.builtin.package',
task=self._task,
connection=self._connection,
play_context=self._play_context,
loader=self._loader,
templar=self._templar,
shared_loader_obj=self._shared_loader_obj)
result = command_action.run(task_vars=task_vars)
return result