分享

中标麒麟系统ansible执⾏yum模块报错的问题分析

在中标麒麟(neokylin)系统中部署某服务,使⽤到了ansible,但是执⾏时发现有yum模块的task报错如下:
TASK [common : Install basic rpms] **************************************************************************
fatal: [node01]: FAILED! => {"changed": false, "msg": ["Could not detect which major revision of yum is in use, which is required to determine module backend.", "Y
报错为yum模块⽆法判断出系统的yum版本,提⽰需要⼿⼯执⾏yum的use_backend参数。同样的task在原⽣RHEL7系统执⾏没有遇到
任何问题,看样⼦调⼊了中标麒麟的某个坑⾥。
问题分析
根据报错,很明确是因为ansible⽆法⾃动判断出系统使⽤的yum版本导致,我们知道当ansible中yum模块不指定use_backend参数时,
将尝试⾃动判断,⽽ansible的setup模块可以获取对应的必要信息, 其中⼀个变量ansible_pkg_mgr及对应yum后端模块,接下来我们执
⾏setup模块输出ansible_pkg_mgr变量来验证下我们的判断:
# ansible -i hosts node01 -m setup -a "filter=ansible_pkg_mgr"
node01 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false
}
果然没有办法获取到ansible_pkg_mgr变量,先看下系统版本信息:
~]# cat /etc/neokylin-release
NeoKylin Linux Advanced Server release V7Update6 (Chromium)
接下来根据报错提⽰信息找到ansible相关代码,在yum.py中,相关代码如下: ansible/plugins/action/yum.py
if module not in ["yum", "yum4", "dnf"]:
facts = self._execute_module(module_name="setup", module_args=dict(filter="ansible_pkg_mgr", gather_subset="!all"), task_vars=task_vars)
display.debug("Facts %s" % facts)
module = facts.get("ansible_facts", {}).get("ansible_pkg_mgr", "auto")
if (not self._task.delegate_to or self._task.delegate_facts) and module != 'auto':
result['ansible_facts'] = {'pkg_mgr': module}
if module != "auto":
if module == "yum4":
module = "dnf"
if module not in self._shared_loader_obj.module_loader:
result.update({'failed': True, 'msg': "Could not find a yum module backend for %s." % module})
else:
# run either the yum (yum3) or dnf (yum4) backend module
new_module_args = self._task.args.copy()
if 'use_backend' in new_module_args:
del new_module_args['use_backend']
display.vvvv("Running %s as the backend for the yum action plugin" % module)
result.update(self._execute_module(module_name=module, module_args=new_module_args, task_vars=task_vars, wrap_async=self._task.async_val)                # Now fall through to cleanup
else:
result.update(
{
'failed': True,
'msg': ("Could not detect which major revision of yum is in use, which is required to determine module backend.",
"You can manually specify use_backend to tell the module whether to use the yum (yum3) or dnf (yum4) backend})"),
}
)
# Now fall through to cleanup
如代码所⽰,当执⾏yum未指定use_backend参数时,ansible会执⾏setup模块并根据ansible_pkg_mgr来⾃动判断yum的版本,获取不
到则会报错,继续看下该参数的获取过程,找到pkg_mgr.py,关键代码如下:
ansible/module_utils/facts/system/pkg_mgr.py
def collect(self, module=None, collected_facts=None):
facts_dict = {}
collected_facts = collected_facts or {}
pkg_mgr_name = 'unknown'
for pkg in PKG_MGRS:
if os.path.exists(pkg['path']):
pkg_mgr_name = pkg['name']
# Handle distro family defaults when more than one package manager is
# installed or available to the distro, the ansible_fact entry should be
# the default package manager officially supported by the distro.
if collected_facts['ansible_os_family'] == "RedHat":
pkg_mgr_name = self._check_rh_versions(pkg_mgr_name, collected_facts)
... ...
def _check_rh_versions(self, pkg_mgr_name, collected_facts):
if c[/'ansible_os_family'][/'name'][/'path'][/'use_backend'][/'ansible_facts'][/"yum", "yum4", "dnf"][/"could not detect which major revision of yum is in use, which is required to determine module backend.", "y
报错为yum模块⽆法判断出系统的yum版本,提⽰需要⼿⼯执⾏yum的use_backend参数。同样的task在原⽣rhel7系统执⾏没有遇到
任何问题,看样⼦调⼊了中标麒麟的某个坑⾥。
问题分析
根据报错,很明确是因为ansible⽆法⾃动判断出系统使⽤的yum版本导致,我们知道当ansible中yum模块不指定use_backend参数时,
将尝试⾃动判断,⽽ansible的setup模块可以获取对应的必要信息, 其中⼀个变量ansible_pkg_mgr及对应yum后端模块,接下来我们执
⾏setup模块输出ansible_pkg_mgr变量来验证下我们的判断:
# ansible -i hosts node01 -m setup -a "filter][/node01][/common : install basic rpms]

试读已结束,请付费阅读全文。

  本文只能试读34%,付费后可阅读全文。 

版权说明:论坛帖子主题均由合作第三方提供并上传,若内容存在侵权,请进行举报

没找到任何评论,期待你打破沉寂

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

联系在线客服