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

467 lines
17 KiB
Python
Raw Normal View History

2020-03-09 10:11:07 +01:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
2020-03-09 10:11:07 +01:00
# (c) 2013, Matthias Vogelgesang <matthias.vogelgesang@gmail.com>
# (c) 2014, Justin Lecher <jlec@gentoo.org>
#
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
---
module: zypper_repository
author: "Matthias Vogelgesang (@matze)"
short_description: Add and remove Zypper repositories
description:
- Add or remove Zypper repositories on SUSE and openSUSE
options:
name:
description:
- A name for the repository. Not required when adding repofiles.
type: str
2020-03-09 10:11:07 +01:00
repo:
description:
- URI of the repository or .repo file. Required when state=present.
type: str
2020-03-09 10:11:07 +01:00
state:
description:
- A source string state.
choices: [ "absent", "present" ]
default: "present"
type: str
2020-03-09 10:11:07 +01:00
description:
description:
- A description of the repository
type: str
2020-03-09 10:11:07 +01:00
disable_gpg_check:
description:
- Whether to disable GPG signature checking of
all packages. Has an effect only if state is
I(present).
- Needs zypper version >= 1.6.2.
type: bool
default: no
2020-03-09 10:11:07 +01:00
autorefresh:
description:
- Enable autorefresh of the repository.
type: bool
default: yes
2020-03-09 10:11:07 +01:00
aliases: [ "refresh" ]
priority:
description:
- Set priority of repository. Packages will always be installed
from the repository with the smallest priority number.
- Needs zypper version >= 1.12.25.
type: int
2020-03-09 10:11:07 +01:00
overwrite_multiple:
description:
- Overwrite multiple repository entries, if repositories with both name and
URL already exist.
type: bool
default: no
2020-03-09 10:11:07 +01:00
auto_import_keys:
description:
- Automatically import the gpg signing key of the new or changed repository.
- Has an effect only if state is I(present). Has no effect on existing (unchanged) repositories or in combination with I(absent).
- Implies runrefresh.
- Only works with C(.repo) files if `name` is given explicitly.
type: bool
default: no
2020-03-09 10:11:07 +01:00
runrefresh:
description:
- Refresh the package list of the given repository.
- Can be used with repo=* to refresh all repositories.
type: bool
default: no
2020-03-09 10:11:07 +01:00
enabled:
description:
- Set repository to enabled (or disabled).
type: bool
default: yes
2020-03-09 10:11:07 +01:00
requirements:
- "zypper >= 1.0 # included in openSUSE >= 11.1 or SUSE Linux Enterprise Server/Desktop >= 11.0"
- python-xml
'''
EXAMPLES = '''
- name: Add NVIDIA repository for graphics drivers
community.general.zypper_repository:
2020-03-09 10:11:07 +01:00
name: nvidia-repo
repo: 'ftp://download.nvidia.com/opensuse/12.2'
state: present
- name: Remove NVIDIA repository
community.general.zypper_repository:
2020-03-09 10:11:07 +01:00
name: nvidia-repo
repo: 'ftp://download.nvidia.com/opensuse/12.2'
state: absent
- name: Add python development repository
community.general.zypper_repository:
2020-03-09 10:11:07 +01:00
repo: 'http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo'
- name: Refresh all repos
community.general.zypper_repository:
2020-03-09 10:11:07 +01:00
repo: '*'
runrefresh: yes
- name: Add a repo and add its gpg key
community.general.zypper_repository:
2020-03-09 10:11:07 +01:00
repo: 'http://download.opensuse.org/repositories/systemsmanagement/openSUSE_Leap_42.1/'
auto_import_keys: yes
- name: Force refresh of a repository
community.general.zypper_repository:
2020-03-09 10:11:07 +01:00
repo: 'http://my_internal_ci_repo/repo'
name: my_ci_repo
state: present
runrefresh: yes
'''
import traceback
XML_IMP_ERR = None
try:
from xml.dom.minidom import parseString as parseXML
HAS_XML = True
except ImportError:
XML_IMP_ERR = traceback.format_exc()
HAS_XML = False
2020-03-09 10:11:07 +01:00
from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
2020-03-09 10:11:07 +01:00
zypper_repository: Improve .repo file idempotency (#3474) (#3528) * If repo option points to .repo file, download for later parsing * Parse downloaded .repo file content (ini format) * Validate downloaded file, map values to repodata, workaround to ignore old .repo related code * Integration Test adjusted to install python package 'requests' first * Revert "Integration Test adjusted to install python package 'requests' first" This reverts commit 0d18352c2238d098831ba6d59b66e731fa8f0cd9. Not allowed to introduce new dependencies at this point, module_utils usage required * Remove python 'requests' dependency, using 'fetch_url' and 'to_text' from 'ansible.module_utils' instead * Prefer alias (name) if given instead repo (url) * If gpgkey was given in .repo file ensure key get automatically imported * ConfigParser Import made Python2 compatible * New .repo code moved below existing run-time parameters checks to keep previous logic * Obsolete workaround removed * two pylint/pep8 errors fixed * name added to autorefresh assert * Missing assert for 'Delete test repo' added * name added to priority option assert * name added to check repo is updated by url assert * name added to check repo is updated by name assert * name added to check add a repo by releasever assert * name added to check remove added repo assert * name added to check add a repo by basearch assert * name added to check remove added repo #2 assert * Bugfix to avoid 'KeyError' Exception in if statements * Refactoring of configparser related code, usage of module_utils, py2 compatibility * Removal of some leftover from earlier testing * Integration tests for add/remove repositories by url to .repo file added * Additional name added to list of test repos that has to be removed * Test added to verify cleanup of local .repo file after removal via zypper * Changelog fragment related to PR #3474 added * yamllint error resolved * Refactoring to reduce indentation and removal of else statements * Integration tests added for loading .repo file from local path * Test .repo file added * Dependency to setup_remote_tmp_dir added * New entry added to 'remove repositories added during test' * Support for .repo file from local path * Changelog: Ref to https://github.com/ansible-collections/community.general/issues/3466 added Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit f0fcb221cd3d279f45bb1b463eb86ed9041324f1) Co-authored-by: Dominik Wombacher <dominik@wombacher.cc>
2021-10-08 07:56:34 +02:00
from ansible.module_utils.urls import fetch_url
from ansible.module_utils.common.text.converters import to_text
from ansible.module_utils.six.moves import configparser, StringIO
from io import open
2020-03-09 10:11:07 +01:00
REPO_OPTS = ['alias', 'name', 'priority', 'enabled', 'autorefresh', 'gpgcheck']
def _get_cmd(module, *args):
2020-03-09 10:11:07 +01:00
"""Combines the non-interactive zypper command with arguments/subcommands"""
cmd = [module.get_bin_path('zypper', required=True), '--quiet', '--non-interactive']
2020-03-09 10:11:07 +01:00
cmd.extend(args)
return cmd
def _parse_repos(module):
"""parses the output of zypper --xmlout repos and return a parse repo dictionary"""
cmd = _get_cmd(module, '--xmlout', 'repos')
2020-03-09 10:11:07 +01:00
if not HAS_XML:
module.fail_json(msg=missing_required_lib("python-xml"), exception=XML_IMP_ERR)
2020-03-09 10:11:07 +01:00
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
if rc == 0:
repos = []
dom = parseXML(stdout)
repo_list = dom.getElementsByTagName('repo')
for repo in repo_list:
opts = {}
for o in REPO_OPTS:
opts[o] = repo.getAttribute(o)
opts['url'] = repo.getElementsByTagName('url')[0].firstChild.data
# A repo can be uniquely identified by an alias + url
repos.append(opts)
return repos
# exit code 6 is ZYPPER_EXIT_NO_REPOS (no repositories defined)
elif rc == 6:
return []
else:
module.fail_json(msg='Failed to execute "%s"' % " ".join(cmd), rc=rc, stdout=stdout, stderr=stderr)
def _repo_changes(module, realrepo, repocmp):
2020-03-09 10:11:07 +01:00
"Check whether the 2 given repos have different settings."
for k in repocmp:
if repocmp[k] and k not in realrepo:
return True
for k, v in realrepo.items():
if k in repocmp and repocmp[k]:
valold = str(repocmp[k] or "")
valnew = v or ""
if k == "url":
if '$releasever' in valold or '$releasever' in valnew:
cmd = ['rpm', '-q', '--qf', '%{version}', '-f', '/etc/os-release']
rc, stdout, stderr = module.run_command(cmd, check_rc=True)
valnew = valnew.replace('$releasever', stdout)
valold = valold.replace('$releasever', stdout)
if '$basearch' in valold or '$basearch' in valnew:
cmd = ['rpm', '-q', '--qf', '%{arch}', '-f', '/etc/os-release']
rc, stdout, stderr = module.run_command(cmd, check_rc=True)
valnew = valnew.replace('$basearch', stdout)
valold = valold.replace('$basearch', stdout)
2020-03-09 10:11:07 +01:00
valold, valnew = valold.rstrip("/"), valnew.rstrip("/")
if valold != valnew:
return True
return False
def repo_exists(module, repodata, overwrite_multiple):
"""Check whether the repository already exists.
returns (exists, mod, old_repos)
exists: whether a matching (name, URL) repo exists
mod: whether there are changes compared to the existing repo
old_repos: list of matching repos
"""
existing_repos = _parse_repos(module)
# look for repos that have matching alias or url to the one searched
repos = []
for kw in ['alias', 'url']:
name = repodata[kw]
for oldr in existing_repos:
if repodata[kw] == oldr[kw] and oldr not in repos:
repos.append(oldr)
if len(repos) == 0:
# Repo does not exist yet
return (False, False, None)
elif len(repos) == 1:
# Found an existing repo, look for changes
has_changes = _repo_changes(module, repos[0], repodata)
2020-03-09 10:11:07 +01:00
return (True, has_changes, repos)
elif len(repos) >= 2:
if overwrite_multiple:
# Found two repos and want to overwrite_multiple
return (True, True, repos)
else:
errmsg = 'More than one repo matched "%s": "%s".' % (name, repos)
errmsg += ' Use overwrite_multiple to allow more than one repo to be overwritten'
module.fail_json(msg=errmsg)
def addmodify_repo(module, repodata, old_repos, zypper_version, warnings):
"Adds the repo, removes old repos before, that would conflict."
repo = repodata['url']
cmd = _get_cmd(module, 'addrepo', '--check')
2020-03-09 10:11:07 +01:00
if repodata['name']:
cmd.extend(['--name', repodata['name']])
# priority on addrepo available since 1.12.25
# https://github.com/openSUSE/zypper/blob/b9b3cb6db76c47dc4c47e26f6a4d2d4a0d12b06d/package/zypper.changes#L327-L336
if repodata['priority']:
if zypper_version >= LooseVersion('1.12.25'):
cmd.extend(['--priority', str(repodata['priority'])])
else:
warnings.append("Setting priority only available for zypper >= 1.12.25. Ignoring priority argument.")
if repodata['enabled'] == '0':
cmd.append('--disable')
# gpgcheck available since 1.6.2
# https://github.com/openSUSE/zypper/blob/b9b3cb6db76c47dc4c47e26f6a4d2d4a0d12b06d/package/zypper.changes#L2446-L2449
# the default changed in the past, so don't assume a default here and show warning for old zypper versions
if zypper_version >= LooseVersion('1.6.2'):
if repodata['gpgcheck'] == '1':
cmd.append('--gpgcheck')
else:
cmd.append('--no-gpgcheck')
else:
warnings.append("Enabling/disabling gpgcheck only available for zypper >= 1.6.2. Using zypper default value.")
if repodata['autorefresh'] == '1':
cmd.append('--refresh')
cmd.append(repo)
if not repo.endswith('.repo'):
cmd.append(repodata['alias'])
if old_repos is not None:
for oldrepo in old_repos:
remove_repo(module, oldrepo['url'])
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
return rc, stdout, stderr
def remove_repo(module, repo):
"Removes the repo."
cmd = _get_cmd(module, 'removerepo', repo)
2020-03-09 10:11:07 +01:00
rc, stdout, stderr = module.run_command(cmd, check_rc=True)
return rc, stdout, stderr
def get_zypper_version(module):
rc, stdout, stderr = module.run_command([module.get_bin_path('zypper', required=True), '--version'])
2020-03-09 10:11:07 +01:00
if rc != 0 or not stdout.startswith('zypper '):
return LooseVersion('1.0')
return LooseVersion(stdout.split()[1])
def runrefreshrepo(module, auto_import_keys=False, shortname=None):
"Forces zypper to refresh repo metadata."
if auto_import_keys:
cmd = _get_cmd(module, '--gpg-auto-import-keys', 'refresh', '--force')
2020-03-09 10:11:07 +01:00
else:
cmd = _get_cmd(module, 'refresh', '--force')
2020-03-09 10:11:07 +01:00
if shortname is not None:
cmd.extend(['-r', shortname])
rc, stdout, stderr = module.run_command(cmd, check_rc=True)
return rc, stdout, stderr
def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(required=False),
repo=dict(required=False),
state=dict(choices=['present', 'absent'], default='present'),
runrefresh=dict(required=False, default=False, type='bool'),
2020-03-09 10:11:07 +01:00
description=dict(required=False),
disable_gpg_check=dict(required=False, default=False, type='bool'),
autorefresh=dict(required=False, default=True, type='bool', aliases=['refresh']),
priority=dict(required=False, type='int'),
enabled=dict(required=False, default=True, type='bool'),
overwrite_multiple=dict(required=False, default=False, type='bool'),
auto_import_keys=dict(required=False, default=False, type='bool'),
),
supports_check_mode=False,
required_one_of=[['state', 'runrefresh']],
)
repo = module.params['repo']
alias = module.params['name']
state = module.params['state']
overwrite_multiple = module.params['overwrite_multiple']
auto_import_keys = module.params['auto_import_keys']
runrefresh = module.params['runrefresh']
zypper_version = get_zypper_version(module)
warnings = [] # collect warning messages for final output
repodata = {
'url': repo,
'alias': alias,
'name': module.params['description'],
'priority': module.params['priority'],
}
# rewrite bools in the language that zypper lr -x provides for easier comparison
if module.params['enabled']:
repodata['enabled'] = '1'
else:
repodata['enabled'] = '0'
if module.params['disable_gpg_check']:
repodata['gpgcheck'] = '0'
else:
repodata['gpgcheck'] = '1'
if module.params['autorefresh']:
repodata['autorefresh'] = '1'
else:
repodata['autorefresh'] = '0'
def exit_unchanged():
module.exit_json(changed=False, repodata=repodata, state=state)
# Check run-time module parameters
if repo == '*' or alias == '*':
if runrefresh:
runrefreshrepo(module, auto_import_keys)
module.exit_json(changed=False, runrefresh=True)
else:
module.fail_json(msg='repo=* can only be used with the runrefresh option.')
if state == 'present' and not repo:
module.fail_json(msg='Module option state=present requires repo')
if state == 'absent' and not repo and not alias:
module.fail_json(msg='Alias or repo parameter required when state=absent')
if repo and repo.endswith('.repo'):
if alias:
module.fail_json(msg='Incompatible option: \'name\'. Do not use name when adding .repo files')
else:
if not alias and state == "present":
module.fail_json(msg='Name required when adding non-repo files.')
zypper_repository: Improve .repo file idempotency (#3474) (#3528) * If repo option points to .repo file, download for later parsing * Parse downloaded .repo file content (ini format) * Validate downloaded file, map values to repodata, workaround to ignore old .repo related code * Integration Test adjusted to install python package 'requests' first * Revert "Integration Test adjusted to install python package 'requests' first" This reverts commit 0d18352c2238d098831ba6d59b66e731fa8f0cd9. Not allowed to introduce new dependencies at this point, module_utils usage required * Remove python 'requests' dependency, using 'fetch_url' and 'to_text' from 'ansible.module_utils' instead * Prefer alias (name) if given instead repo (url) * If gpgkey was given in .repo file ensure key get automatically imported * ConfigParser Import made Python2 compatible * New .repo code moved below existing run-time parameters checks to keep previous logic * Obsolete workaround removed * two pylint/pep8 errors fixed * name added to autorefresh assert * Missing assert for 'Delete test repo' added * name added to priority option assert * name added to check repo is updated by url assert * name added to check repo is updated by name assert * name added to check add a repo by releasever assert * name added to check remove added repo assert * name added to check add a repo by basearch assert * name added to check remove added repo #2 assert * Bugfix to avoid 'KeyError' Exception in if statements * Refactoring of configparser related code, usage of module_utils, py2 compatibility * Removal of some leftover from earlier testing * Integration tests for add/remove repositories by url to .repo file added * Additional name added to list of test repos that has to be removed * Test added to verify cleanup of local .repo file after removal via zypper * Changelog fragment related to PR #3474 added * yamllint error resolved * Refactoring to reduce indentation and removal of else statements * Integration tests added for loading .repo file from local path * Test .repo file added * Dependency to setup_remote_tmp_dir added * New entry added to 'remove repositories added during test' * Support for .repo file from local path * Changelog: Ref to https://github.com/ansible-collections/community.general/issues/3466 added Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit f0fcb221cd3d279f45bb1b463eb86ed9041324f1) Co-authored-by: Dominik Wombacher <dominik@wombacher.cc>
2021-10-08 07:56:34 +02:00
# Download / Open and parse .repo file to ensure idempotency
if repo and repo.endswith('.repo'):
if repo.startswith(('http://', 'https://')):
response, info = fetch_url(module=module, url=repo, force=True)
if not response or info['status'] != 200:
module.fail_json(msg='Error downloading .repo file from provided URL')
repofile_text = to_text(response.read(), errors='surrogate_or_strict')
else:
try:
with open(repo, encoding='utf-8') as file:
repofile_text = file.read()
except IOError:
module.fail_json(msg='Error opening .repo file from provided path')
repofile = configparser.ConfigParser()
try:
repofile.readfp(StringIO(repofile_text))
except configparser.Error:
module.fail_json(msg='Invalid format, .repo file could not be parsed')
# No support for .repo file with zero or more than one repository
if len(repofile.sections()) != 1:
err = "Invalid format, .repo file contains %s repositories, expected 1" % len(repofile.sections())
module.fail_json(msg=err)
section = repofile.sections()[0]
repofile_items = dict(repofile.items(section))
# Only proceed if at least baseurl is available
if 'baseurl' not in repofile_items:
module.fail_json(msg='No baseurl found in .repo file')
# Set alias (name) and url based on values from .repo file
alias = section
repodata['alias'] = section
repodata['url'] = repofile_items['baseurl']
# If gpgkey is part of the .repo file, auto import key
if 'gpgkey' in repofile_items:
auto_import_keys = True
# Map additional values, if available
if 'name' in repofile_items:
repodata['name'] = repofile_items['name']
if 'enabled' in repofile_items:
repodata['enabled'] = repofile_items['enabled']
if 'autorefresh' in repofile_items:
repodata['autorefresh'] = repofile_items['autorefresh']
if 'gpgcheck' in repofile_items:
repodata['gpgcheck'] = repofile_items['gpgcheck']
2020-03-09 10:11:07 +01:00
exists, mod, old_repos = repo_exists(module, repodata, overwrite_multiple)
zypper_repository: Improve .repo file idempotency (#3474) (#3528) * If repo option points to .repo file, download for later parsing * Parse downloaded .repo file content (ini format) * Validate downloaded file, map values to repodata, workaround to ignore old .repo related code * Integration Test adjusted to install python package 'requests' first * Revert "Integration Test adjusted to install python package 'requests' first" This reverts commit 0d18352c2238d098831ba6d59b66e731fa8f0cd9. Not allowed to introduce new dependencies at this point, module_utils usage required * Remove python 'requests' dependency, using 'fetch_url' and 'to_text' from 'ansible.module_utils' instead * Prefer alias (name) if given instead repo (url) * If gpgkey was given in .repo file ensure key get automatically imported * ConfigParser Import made Python2 compatible * New .repo code moved below existing run-time parameters checks to keep previous logic * Obsolete workaround removed * two pylint/pep8 errors fixed * name added to autorefresh assert * Missing assert for 'Delete test repo' added * name added to priority option assert * name added to check repo is updated by url assert * name added to check repo is updated by name assert * name added to check add a repo by releasever assert * name added to check remove added repo assert * name added to check add a repo by basearch assert * name added to check remove added repo #2 assert * Bugfix to avoid 'KeyError' Exception in if statements * Refactoring of configparser related code, usage of module_utils, py2 compatibility * Removal of some leftover from earlier testing * Integration tests for add/remove repositories by url to .repo file added * Additional name added to list of test repos that has to be removed * Test added to verify cleanup of local .repo file after removal via zypper * Changelog fragment related to PR #3474 added * yamllint error resolved * Refactoring to reduce indentation and removal of else statements * Integration tests added for loading .repo file from local path * Test .repo file added * Dependency to setup_remote_tmp_dir added * New entry added to 'remove repositories added during test' * Support for .repo file from local path * Changelog: Ref to https://github.com/ansible-collections/community.general/issues/3466 added Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit f0fcb221cd3d279f45bb1b463eb86ed9041324f1) Co-authored-by: Dominik Wombacher <dominik@wombacher.cc>
2021-10-08 07:56:34 +02:00
if alias:
2020-03-09 10:11:07 +01:00
shortname = alias
zypper_repository: Improve .repo file idempotency (#3474) (#3528) * If repo option points to .repo file, download for later parsing * Parse downloaded .repo file content (ini format) * Validate downloaded file, map values to repodata, workaround to ignore old .repo related code * Integration Test adjusted to install python package 'requests' first * Revert "Integration Test adjusted to install python package 'requests' first" This reverts commit 0d18352c2238d098831ba6d59b66e731fa8f0cd9. Not allowed to introduce new dependencies at this point, module_utils usage required * Remove python 'requests' dependency, using 'fetch_url' and 'to_text' from 'ansible.module_utils' instead * Prefer alias (name) if given instead repo (url) * If gpgkey was given in .repo file ensure key get automatically imported * ConfigParser Import made Python2 compatible * New .repo code moved below existing run-time parameters checks to keep previous logic * Obsolete workaround removed * two pylint/pep8 errors fixed * name added to autorefresh assert * Missing assert for 'Delete test repo' added * name added to priority option assert * name added to check repo is updated by url assert * name added to check repo is updated by name assert * name added to check add a repo by releasever assert * name added to check remove added repo assert * name added to check add a repo by basearch assert * name added to check remove added repo #2 assert * Bugfix to avoid 'KeyError' Exception in if statements * Refactoring of configparser related code, usage of module_utils, py2 compatibility * Removal of some leftover from earlier testing * Integration tests for add/remove repositories by url to .repo file added * Additional name added to list of test repos that has to be removed * Test added to verify cleanup of local .repo file after removal via zypper * Changelog fragment related to PR #3474 added * yamllint error resolved * Refactoring to reduce indentation and removal of else statements * Integration tests added for loading .repo file from local path * Test .repo file added * Dependency to setup_remote_tmp_dir added * New entry added to 'remove repositories added during test' * Support for .repo file from local path * Changelog: Ref to https://github.com/ansible-collections/community.general/issues/3466 added Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit f0fcb221cd3d279f45bb1b463eb86ed9041324f1) Co-authored-by: Dominik Wombacher <dominik@wombacher.cc>
2021-10-08 07:56:34 +02:00
else:
shortname = repo
2020-03-09 10:11:07 +01:00
if state == 'present':
if exists and not mod:
if runrefresh:
runrefreshrepo(module, auto_import_keys, shortname)
exit_unchanged()
rc, stdout, stderr = addmodify_repo(module, repodata, old_repos, zypper_version, warnings)
if rc == 0 and (runrefresh or auto_import_keys):
runrefreshrepo(module, auto_import_keys, shortname)
elif state == 'absent':
if not exists:
exit_unchanged()
rc, stdout, stderr = remove_repo(module, shortname)
if rc == 0:
module.exit_json(changed=True, repodata=repodata, state=state, warnings=warnings)
else:
module.fail_json(msg="Zypper failed with rc %s" % rc, rc=rc, stdout=stdout, stderr=stderr, repodata=repodata, state=state, warnings=warnings)
if __name__ == '__main__':
main()