2013-11-06 18:17:34 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
# (c) 2013, Matthias Vogelgesang <matthias.vogelgesang@gmail.com>
|
2015-01-09 16:07:42 +01:00
|
|
|
# (c) 2014, Justin Lecher <jlec@gentoo.org>
|
2013-11-06 18:17:34 +01:00
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: zypper_repository
|
2015-05-14 16:45:21 +02:00
|
|
|
author: '"Matthias Vogelgesang (@matze)" <matthias.vogelgesang@gmail.com>'
|
2013-11-06 18:17:34 +01:00
|
|
|
version_added: "1.4"
|
|
|
|
short_description: Add and remove Zypper repositories
|
|
|
|
description:
|
|
|
|
- Add or remove Zypper repositories on SUSE and openSUSE
|
|
|
|
options:
|
|
|
|
name:
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
required: false
|
2013-11-06 18:17:34 +01:00
|
|
|
default: none
|
|
|
|
description:
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
- A name for the repository. Not required when adding repofiles.
|
2013-11-06 18:17:34 +01:00
|
|
|
repo:
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
required: false
|
2013-11-06 18:17:34 +01:00
|
|
|
default: none
|
|
|
|
description:
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
- URI of the repository or .repo file. Required when state=present.
|
2013-11-06 18:17:34 +01:00
|
|
|
state:
|
|
|
|
required: false
|
|
|
|
choices: [ "absent", "present" ]
|
|
|
|
default: "present"
|
|
|
|
description:
|
|
|
|
- A source string state.
|
|
|
|
description:
|
|
|
|
required: false
|
|
|
|
default: none
|
|
|
|
description:
|
|
|
|
- A description of the repository
|
|
|
|
disable_gpg_check:
|
|
|
|
description:
|
2015-01-15 05:49:44 +01:00
|
|
|
- Whether to disable GPG signature checking of
|
|
|
|
all packages. Has an effect only if state is
|
|
|
|
I(present).
|
2013-11-06 18:17:34 +01:00
|
|
|
required: false
|
|
|
|
default: "no"
|
|
|
|
choices: [ "yes", "no" ]
|
|
|
|
aliases: []
|
2015-01-09 16:07:42 +01:00
|
|
|
refresh:
|
2015-01-15 05:49:44 +01:00
|
|
|
description:
|
|
|
|
- Enable autorefresh of the repository.
|
2015-01-09 16:07:42 +01:00
|
|
|
required: false
|
2015-01-14 15:50:18 +01:00
|
|
|
default: "yes"
|
2015-01-09 16:07:42 +01:00
|
|
|
choices: [ "yes", "no" ]
|
|
|
|
aliases: []
|
2013-11-06 18:17:34 +01:00
|
|
|
notes: []
|
|
|
|
requirements: [ zypper ]
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
# Add NVIDIA repository for graphics drivers
|
|
|
|
- zypper_repository: name=nvidia-repo repo='ftp://download.nvidia.com/opensuse/12.2' state=present
|
|
|
|
|
|
|
|
# Remove NVIDIA repository
|
|
|
|
- zypper_repository: name=nvidia-repo repo='ftp://download.nvidia.com/opensuse/12.2' state=absent
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
|
|
|
|
# Add python development repository
|
|
|
|
- zypper_repository: repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo
|
2013-11-06 18:17:34 +01:00
|
|
|
'''
|
|
|
|
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
REPO_OPTS = ['alias', 'name', 'priority', 'enabled', 'autorefresh', 'gpgcheck']
|
2013-11-06 18:17:34 +01:00
|
|
|
|
2014-10-10 19:51:44 +02:00
|
|
|
def zypper_version(module):
|
|
|
|
"""Return (rc, message) tuple"""
|
|
|
|
cmd = ['/usr/bin/zypper', '-V']
|
|
|
|
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
|
|
|
if rc == 0:
|
|
|
|
return rc, stdout
|
|
|
|
else:
|
|
|
|
return rc, stderr
|
2013-11-06 18:17:34 +01:00
|
|
|
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
def _parse_repos(module):
|
|
|
|
"""parses the output of zypper -x lr and returns a parse repo dictionary"""
|
|
|
|
cmd = ['/usr/bin/zypper', '-x', 'lr']
|
|
|
|
repos = []
|
|
|
|
|
2014-10-10 19:51:44 +02:00
|
|
|
from xml.dom.minidom import parseString as parseXML
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
rc, stdout, stderr = module.run_command(cmd, check_rc=True)
|
|
|
|
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
|
|
|
|
|
2014-10-10 19:51:44 +02:00
|
|
|
def _parse_repos_old(module):
|
|
|
|
"""parses the output of zypper sl and returns a parse repo dictionary"""
|
|
|
|
cmd = ['/usr/bin/zypper', 'sl']
|
|
|
|
repos = []
|
|
|
|
rc, stdout, stderr = module.run_command(cmd, check_rc=True)
|
|
|
|
for line in stdout.split('\n'):
|
|
|
|
matched = re.search(r'\d+\s+\|\s+(?P<enabled>\w+)\s+\|\s+(?P<autorefresh>\w+)\s+\|\s+(?P<type>\w+)\s+\|\s+(?P<name>\w+)\s+\|\s+(?P<url>.*)', line)
|
|
|
|
if matched == None:
|
|
|
|
continue
|
|
|
|
|
|
|
|
m = matched.groupdict()
|
|
|
|
m['alias']= m['name']
|
|
|
|
m['priority'] = 100
|
|
|
|
m['gpgcheck'] = 1
|
|
|
|
repos.append(m)
|
|
|
|
|
|
|
|
return repos
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
|
2014-10-10 19:51:44 +02:00
|
|
|
def repo_exists(module, old_zypper, **kwargs):
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
|
|
|
|
def repo_subset(realrepo, repocmp):
|
|
|
|
for k in repocmp:
|
|
|
|
if k not in realrepo:
|
|
|
|
return False
|
|
|
|
|
|
|
|
for k, v in realrepo.items():
|
|
|
|
if k in repocmp:
|
2014-09-09 09:22:08 +02:00
|
|
|
if v.rstrip("/") != repocmp[k].rstrip("/"):
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2014-10-10 19:51:44 +02:00
|
|
|
if old_zypper:
|
|
|
|
repos = _parse_repos_old(module)
|
|
|
|
else:
|
|
|
|
repos = _parse_repos(module)
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
|
|
|
|
for repo in repos:
|
|
|
|
if repo_subset(repo, kwargs):
|
|
|
|
return True
|
|
|
|
return False
|
2013-11-06 18:17:34 +01:00
|
|
|
|
|
|
|
|
2015-01-09 16:07:42 +01:00
|
|
|
def add_repo(module, repo, alias, description, disable_gpg_check, old_zypper, refresh):
|
2014-10-10 19:51:44 +02:00
|
|
|
if old_zypper:
|
|
|
|
cmd = ['/usr/bin/zypper', 'sa']
|
|
|
|
else:
|
2015-01-09 16:07:42 +01:00
|
|
|
cmd = ['/usr/bin/zypper', 'ar', '--check']
|
2014-10-10 19:51:44 +02:00
|
|
|
|
|
|
|
if repo.startswith("file:/") and old_zypper:
|
|
|
|
cmd.extend(['-t', 'Plaindir'])
|
|
|
|
else:
|
|
|
|
cmd.extend(['-t', 'plaindir'])
|
2013-11-06 18:17:34 +01:00
|
|
|
|
|
|
|
if description:
|
|
|
|
cmd.extend(['--name', description])
|
|
|
|
|
2014-10-10 19:51:44 +02:00
|
|
|
if disable_gpg_check and not old_zypper:
|
2013-11-06 18:17:34 +01:00
|
|
|
cmd.append('--no-gpgcheck')
|
|
|
|
|
2015-01-09 16:07:42 +01:00
|
|
|
if refresh:
|
|
|
|
cmd.append('--refresh')
|
|
|
|
|
2013-11-06 18:17:34 +01:00
|
|
|
cmd.append(repo)
|
|
|
|
|
|
|
|
if not repo.endswith('.repo'):
|
|
|
|
cmd.append(alias)
|
|
|
|
|
|
|
|
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
|
|
|
changed = rc == 0
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
if rc == 0:
|
|
|
|
changed = True
|
|
|
|
elif 'already exists. Please use another alias' in stderr:
|
|
|
|
changed = False
|
|
|
|
else:
|
2014-10-10 19:51:44 +02:00
|
|
|
#module.fail_json(msg=stderr if stderr else stdout)
|
|
|
|
if stderr:
|
|
|
|
module.fail_json(msg=stderr)
|
|
|
|
else:
|
|
|
|
module.fail_json(msg=stdout)
|
2013-11-06 18:17:34 +01:00
|
|
|
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
return changed
|
2013-11-06 18:17:34 +01:00
|
|
|
|
|
|
|
|
2014-10-10 19:51:44 +02:00
|
|
|
def remove_repo(module, repo, alias, old_zypper):
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
|
2014-10-10 19:51:44 +02:00
|
|
|
if old_zypper:
|
|
|
|
cmd = ['/usr/bin/zypper', 'sd']
|
|
|
|
else:
|
|
|
|
cmd = ['/usr/bin/zypper', 'rr']
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
if alias:
|
|
|
|
cmd.append(alias)
|
|
|
|
else:
|
|
|
|
cmd.append(repo)
|
|
|
|
|
|
|
|
rc, stdout, stderr = module.run_command(cmd, check_rc=True)
|
2013-11-06 18:17:34 +01:00
|
|
|
changed = rc == 0
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
return changed
|
2013-11-06 18:17:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
def fail_if_rc_is_null(module, rc, stdout, stderr):
|
|
|
|
if rc != 0:
|
2014-10-10 19:51:44 +02:00
|
|
|
#module.fail_json(msg=stderr if stderr else stdout)
|
|
|
|
if stderr:
|
|
|
|
module.fail_json(msg=stderr)
|
|
|
|
else:
|
|
|
|
module.fail_json(msg=stdout)
|
2013-11-06 18:17:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
name=dict(required=False),
|
|
|
|
repo=dict(required=False),
|
2013-11-06 18:17:34 +01:00
|
|
|
state=dict(choices=['present', 'absent'], default='present'),
|
|
|
|
description=dict(required=False),
|
|
|
|
disable_gpg_check = dict(required=False, default='no', type='bool'),
|
2015-01-09 16:07:42 +01:00
|
|
|
refresh = dict(required=False, default='yes', type='bool'),
|
2013-11-06 18:17:34 +01:00
|
|
|
),
|
2014-01-14 14:20:18 +01:00
|
|
|
supports_check_mode=False,
|
2013-11-06 18:17:34 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
repo = module.params['repo']
|
|
|
|
state = module.params['state']
|
|
|
|
name = module.params['name']
|
|
|
|
description = module.params['description']
|
|
|
|
disable_gpg_check = module.params['disable_gpg_check']
|
2015-01-09 16:07:42 +01:00
|
|
|
refresh = module.params['refresh']
|
2013-11-06 18:17:34 +01:00
|
|
|
|
|
|
|
def exit_unchanged():
|
|
|
|
module.exit_json(changed=False, repo=repo, state=state, name=name)
|
|
|
|
|
2014-10-10 19:51:44 +02:00
|
|
|
rc, out = zypper_version(module)
|
|
|
|
match = re.match(r'zypper\s+(\d+)\.(\d+)\.(\d+)', out)
|
|
|
|
if not match or int(match.group(1)) > 0:
|
|
|
|
old_zypper = False
|
|
|
|
else:
|
|
|
|
old_zypper = True
|
|
|
|
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
# Check run-time module parameters
|
|
|
|
if state == 'present' and not repo:
|
|
|
|
module.fail_json(msg='Module option state=present requires repo')
|
|
|
|
if state == 'absent' and not repo and not name:
|
|
|
|
module.fail_json(msg='Alias or repo parameter required when state=absent')
|
|
|
|
|
|
|
|
if repo and repo.endswith('.repo'):
|
|
|
|
if name:
|
|
|
|
module.fail_json(msg='Incompatible option: \'name\'. Do not use name when adding repo files')
|
|
|
|
else:
|
2014-09-04 14:35:39 +02:00
|
|
|
if not name and state == "present":
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
module.fail_json(msg='Name required when adding non-repo files:')
|
|
|
|
|
|
|
|
if repo and repo.endswith('.repo'):
|
2014-10-10 19:51:44 +02:00
|
|
|
exists = repo_exists(module, old_zypper, url=repo, alias=name)
|
2014-09-04 14:35:39 +02:00
|
|
|
elif repo:
|
2014-10-10 19:51:44 +02:00
|
|
|
exists = repo_exists(module, old_zypper, url=repo)
|
Correctly handle .repo files in zypper_repository module
Before the changes, removing a repository required a repo url. This shouldn't be required since zypper allows removing a repo based on its alias (mapped to name in this module).
The name variable was always required, which is misleading since repofiles provide their own alias. So a runtime check was added to avoid this confusion.
Additionaly, running this module on .repo files weren't idempotent. e.g
Before:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo name=foo"
{"msg": "Repository named 'devel_languages_python' already exists. Please use another alias.\n", "failed": true}
After:
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": true}
$ ./hacking/test-module -m library/packaging/zypper_repository -a "repo=http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo"
{"repo": "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_11_SP3/devel:languages:python.repo", "state": "present", "changed": false}
Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
2014-06-24 08:10:57 +02:00
|
|
|
else:
|
2014-10-10 19:51:44 +02:00
|
|
|
exists = repo_exists(module, old_zypper, alias=name)
|
2013-11-06 18:17:34 +01:00
|
|
|
|
|
|
|
if state == 'present':
|
|
|
|
if exists:
|
|
|
|
exit_unchanged()
|
|
|
|
|
2015-01-09 16:07:42 +01:00
|
|
|
changed = add_repo(module, repo, name, description, disable_gpg_check, old_zypper, refresh)
|
2013-11-06 18:17:34 +01:00
|
|
|
elif state == 'absent':
|
|
|
|
if not exists:
|
|
|
|
exit_unchanged()
|
|
|
|
|
2014-10-10 19:51:44 +02:00
|
|
|
changed = remove_repo(module, repo, name, old_zypper)
|
2013-11-06 18:17:34 +01:00
|
|
|
|
|
|
|
module.exit_json(changed=changed, repo=repo, state=state)
|
|
|
|
|
2013-12-02 21:13:49 +01:00
|
|
|
# import module snippets
|
2013-12-02 21:11:23 +01:00
|
|
|
from ansible.module_utils.basic import *
|
2013-11-06 18:17:34 +01:00
|
|
|
|
|
|
|
main()
|