Add type property to zypper
To install patterns and other package types a type parameter needs to be specified to zypper.
This commit is contained in:
parent
21fce8ac73
commit
44280e461c
1 changed files with 19 additions and 11 deletions
|
@ -50,6 +50,12 @@ options:
|
|||
required: false
|
||||
choices: [ present, latest, absent ]
|
||||
default: "present"
|
||||
type:
|
||||
description:
|
||||
- The type of package to be operated on.
|
||||
required: false
|
||||
choices: [ package, patch, pattern, product, srcpackage ]
|
||||
default: "package"
|
||||
disable_gpg_check:
|
||||
description:
|
||||
- Whether to disable to GPG signature checking of the package
|
||||
|
@ -148,7 +154,7 @@ def get_package_state(m, packages):
|
|||
return installed_state
|
||||
|
||||
# Function used to make sure a package is present.
|
||||
def package_present(m, name, installed_state, disable_gpg_check, disable_recommends, old_zypper):
|
||||
def package_present(m, name, installed_state, package_type, disable_gpg_check, disable_recommends, old_zypper):
|
||||
packages = []
|
||||
for package in name:
|
||||
if installed_state[package] is False:
|
||||
|
@ -158,7 +164,7 @@ def package_present(m, name, installed_state, disable_gpg_check, disable_recomme
|
|||
# add global options before zypper command
|
||||
if disable_gpg_check:
|
||||
cmd.append('--no-gpg-checks')
|
||||
cmd.extend(['install', '--auto-agree-with-licenses'])
|
||||
cmd.extend(['install', '--auto-agree-with-licenses', '-t', package_type])
|
||||
# add install parameter
|
||||
if disable_recommends and not old_zypper:
|
||||
cmd.append('--no-recommends')
|
||||
|
@ -178,10 +184,10 @@ def package_present(m, name, installed_state, disable_gpg_check, disable_recomme
|
|||
return (rc, stdout, stderr, changed)
|
||||
|
||||
# Function used to make sure a package is the latest available version.
|
||||
def package_latest(m, name, installed_state, disable_gpg_check, disable_recommends, old_zypper):
|
||||
def package_latest(m, name, installed_state, package_type, disable_gpg_check, disable_recommends, old_zypper):
|
||||
|
||||
# first of all, make sure all the packages are installed
|
||||
(rc, stdout, stderr, changed) = package_present(m, name, installed_state, disable_gpg_check, disable_recommends, old_zypper)
|
||||
(rc, stdout, stderr, changed) = package_present(m, name, installed_state, package_type, disable_gpg_check, disable_recommends, old_zypper)
|
||||
|
||||
# if we've already made a change, we don't have to check whether a version changed
|
||||
if not changed:
|
||||
|
@ -193,9 +199,9 @@ def package_latest(m, name, installed_state, disable_gpg_check, disable_recommen
|
|||
cmd.append('--no-gpg-checks')
|
||||
|
||||
if old_zypper:
|
||||
cmd.extend(['install', '--auto-agree-with-licenses'])
|
||||
cmd.extend(['install', '--auto-agree-with-licenses', '-t', package_type])
|
||||
else:
|
||||
cmd.extend(['update', '--auto-agree-with-licenses'])
|
||||
cmd.extend(['update', '--auto-agree-with-licenses', '-t', package_type])
|
||||
|
||||
cmd.extend(name)
|
||||
rc, stdout, stderr = m.run_command(cmd, check_rc=False)
|
||||
|
@ -209,13 +215,13 @@ def package_latest(m, name, installed_state, disable_gpg_check, disable_recommen
|
|||
return (rc, stdout, stderr, changed)
|
||||
|
||||
# Function used to make sure a package is not installed.
|
||||
def package_absent(m, name, installed_state, old_zypper):
|
||||
def package_absent(m, name, installed_state, package_type, old_zypper):
|
||||
packages = []
|
||||
for package in name:
|
||||
if installed_state[package] is True:
|
||||
packages.append(package)
|
||||
if len(packages) != 0:
|
||||
cmd = ['/usr/bin/zypper', '--non-interactive', 'remove']
|
||||
cmd = ['/usr/bin/zypper', '--non-interactive', 'remove', '-t', package_type]
|
||||
cmd.extend(packages)
|
||||
rc, stdout, stderr = m.run_command(cmd)
|
||||
|
||||
|
@ -239,6 +245,7 @@ def main():
|
|||
argument_spec = dict(
|
||||
name = dict(required=True, aliases=['pkg'], type='list'),
|
||||
state = dict(required=False, default='present', choices=['absent', 'installed', 'latest', 'present', 'removed']),
|
||||
type = dict(required=False, default='package', choices=['package', 'patch', 'pattern', 'product', 'srcpackage']),
|
||||
disable_gpg_check = dict(required=False, default='no', type='bool'),
|
||||
disable_recommends = dict(required=False, default='yes', type='bool'),
|
||||
),
|
||||
|
@ -250,6 +257,7 @@ def main():
|
|||
|
||||
name = params['name']
|
||||
state = params['state']
|
||||
type_ = params['type']
|
||||
disable_gpg_check = params['disable_gpg_check']
|
||||
disable_recommends = params['disable_recommends']
|
||||
|
||||
|
@ -272,11 +280,11 @@ def main():
|
|||
|
||||
# Perform requested action
|
||||
if state in ['installed', 'present']:
|
||||
(rc, stdout, stderr, changed) = package_present(module, name, installed_state, disable_gpg_check, disable_recommends, old_zypper)
|
||||
(rc, stdout, stderr, changed) = package_present(module, name, installed_state, type_, disable_gpg_check, disable_recommends, old_zypper)
|
||||
elif state in ['absent', 'removed']:
|
||||
(rc, stdout, stderr, changed) = package_absent(module, name, installed_state, old_zypper)
|
||||
(rc, stdout, stderr, changed) = package_absent(module, name, installed_state, type_, old_zypper)
|
||||
elif state == 'latest':
|
||||
(rc, stdout, stderr, changed) = package_latest(module, name, installed_state, disable_gpg_check, disable_recommends, old_zypper)
|
||||
(rc, stdout, stderr, changed) = package_latest(module, name, installed_state, type_, disable_gpg_check, disable_recommends, old_zypper)
|
||||
|
||||
if rc != 0:
|
||||
if stderr:
|
||||
|
|
Loading…
Reference in a new issue