1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Start zypper in non-interactive mode (#2854)

This commit is contained in:
Alex 2016-09-10 08:36:59 +02:00 committed by Matt Clay
parent d34f3b4c05
commit e2795d1401

View file

@ -129,9 +129,17 @@ REPO_OPTS = ['alias', 'name', 'priority', 'enabled', 'autorefresh', 'gpgcheck']
from distutils.version import LooseVersion from distutils.version import LooseVersion
def _get_cmd(*args):
"""Combines the non-interactive zypper command with arguments/subcommands"""
cmd = ['/usr/bin/zypper', '--quiet', '--non-interactive']
cmd.extend(args)
return cmd
def _parse_repos(module): def _parse_repos(module):
"""parses the output of zypper -x lr and return a parse repo dictionary""" """parses the output of zypper --xmlout repos and return a parse repo dictionary"""
cmd = ['/usr/bin/zypper', '-x', 'lr'] cmd = _get_cmd('--xmlout', 'repos')
from xml.dom.minidom import parseString as parseXML from xml.dom.minidom import parseString as parseXML
rc, stdout, stderr = module.run_command(cmd, check_rc=False) rc, stdout, stderr = module.run_command(cmd, check_rc=False)
@ -207,7 +215,7 @@ def repo_exists(module, repodata, overwrite_multiple):
def addmodify_repo(module, repodata, old_repos, zypper_version, warnings): def addmodify_repo(module, repodata, old_repos, zypper_version, warnings):
"Adds the repo, removes old repos before, that would conflict." "Adds the repo, removes old repos before, that would conflict."
repo = repodata['url'] repo = repodata['url']
cmd = ['/usr/bin/zypper', 'ar', '--check'] cmd = _get_cmd('addrepo', '--check')
if repodata['name']: if repodata['name']:
cmd.extend(['--name', repodata['name']]) cmd.extend(['--name', repodata['name']])
@ -251,7 +259,7 @@ def addmodify_repo(module, repodata, old_repos, zypper_version, warnings):
def remove_repo(module, repo): def remove_repo(module, repo):
"Removes the repo." "Removes the repo."
cmd = ['/usr/bin/zypper', 'rr', repo] cmd = _get_cmd('removerepo', repo)
rc, stdout, stderr = module.run_command(cmd, check_rc=True) rc, stdout, stderr = module.run_command(cmd, check_rc=True)
return rc, stdout, stderr return rc, stdout, stderr
@ -265,7 +273,7 @@ def get_zypper_version(module):
def runrefreshrepo(module, auto_import_keys=False, shortname=None): def runrefreshrepo(module, auto_import_keys=False, shortname=None):
"Forces zypper to refresh repo metadata." "Forces zypper to refresh repo metadata."
cmd = ['/usr/bin/zypper', 'refresh', '--force'] cmd = _get_cmd('refresh', '--force')
if auto_import_keys: if auto_import_keys:
cmd.append('--gpg-auto-import-keys') cmd.append('--gpg-auto-import-keys')
if shortname is not None: if shortname is not None: