|
|
@ -50,6 +50,12 @@ options:
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
choices: [ present, latest, absent ]
|
|
|
|
choices: [ present, latest, absent ]
|
|
|
|
default: "present"
|
|
|
|
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:
|
|
|
|
disable_gpg_check:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Whether to disable to GPG signature checking of the package
|
|
|
|
- Whether to disable to GPG signature checking of the package
|
|
|
@ -148,7 +154,7 @@ def get_package_state(m, packages):
|
|
|
|
return installed_state
|
|
|
|
return installed_state
|
|
|
|
|
|
|
|
|
|
|
|
# Function used to make sure a package is present.
|
|
|
|
# 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 = []
|
|
|
|
packages = []
|
|
|
|
for package in name:
|
|
|
|
for package in name:
|
|
|
|
if installed_state[package] is False:
|
|
|
|
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
|
|
|
|
# add global options before zypper command
|
|
|
|
if disable_gpg_check:
|
|
|
|
if disable_gpg_check:
|
|
|
|
cmd.append('--no-gpg-checks')
|
|
|
|
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
|
|
|
|
# add install parameter
|
|
|
|
if disable_recommends and not old_zypper:
|
|
|
|
if disable_recommends and not old_zypper:
|
|
|
|
cmd.append('--no-recommends')
|
|
|
|
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)
|
|
|
|
return (rc, stdout, stderr, changed)
|
|
|
|
|
|
|
|
|
|
|
|
# Function used to make sure a package is the latest available version.
|
|
|
|
# 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
|
|
|
|
# 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 we've already made a change, we don't have to check whether a version changed
|
|
|
|
if not 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')
|
|
|
|
cmd.append('--no-gpg-checks')
|
|
|
|
|
|
|
|
|
|
|
|
if old_zypper:
|
|
|
|
if old_zypper:
|
|
|
|
cmd.extend(['install', '--auto-agree-with-licenses'])
|
|
|
|
cmd.extend(['install', '--auto-agree-with-licenses', '-t', package_type])
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
cmd.extend(['update', '--auto-agree-with-licenses'])
|
|
|
|
cmd.extend(['update', '--auto-agree-with-licenses', '-t', package_type])
|
|
|
|
|
|
|
|
|
|
|
|
cmd.extend(name)
|
|
|
|
cmd.extend(name)
|
|
|
|
rc, stdout, stderr = m.run_command(cmd, check_rc=False)
|
|
|
|
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)
|
|
|
|
return (rc, stdout, stderr, changed)
|
|
|
|
|
|
|
|
|
|
|
|
# Function used to make sure a package is not installed.
|
|
|
|
# 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 = []
|
|
|
|
packages = []
|
|
|
|
for package in name:
|
|
|
|
for package in name:
|
|
|
|
if installed_state[package] is True:
|
|
|
|
if installed_state[package] is True:
|
|
|
|
packages.append(package)
|
|
|
|
packages.append(package)
|
|
|
|
if len(packages) != 0:
|
|
|
|
if len(packages) != 0:
|
|
|
|
cmd = ['/usr/bin/zypper', '--non-interactive', 'remove']
|
|
|
|
cmd = ['/usr/bin/zypper', '--non-interactive', 'remove', '-t', package_type]
|
|
|
|
cmd.extend(packages)
|
|
|
|
cmd.extend(packages)
|
|
|
|
rc, stdout, stderr = m.run_command(cmd)
|
|
|
|
rc, stdout, stderr = m.run_command(cmd)
|
|
|
|
|
|
|
|
|
|
|
@ -239,6 +245,7 @@ def main():
|
|
|
|
argument_spec = dict(
|
|
|
|
argument_spec = dict(
|
|
|
|
name = dict(required=True, aliases=['pkg'], type='list'),
|
|
|
|
name = dict(required=True, aliases=['pkg'], type='list'),
|
|
|
|
state = dict(required=False, default='present', choices=['absent', 'installed', 'latest', 'present', 'removed']),
|
|
|
|
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_gpg_check = dict(required=False, default='no', type='bool'),
|
|
|
|
disable_recommends = dict(required=False, default='yes', type='bool'),
|
|
|
|
disable_recommends = dict(required=False, default='yes', type='bool'),
|
|
|
|
),
|
|
|
|
),
|
|
|
@ -250,6 +257,7 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
name = params['name']
|
|
|
|
name = params['name']
|
|
|
|
state = params['state']
|
|
|
|
state = params['state']
|
|
|
|
|
|
|
|
type_ = params['type']
|
|
|
|
disable_gpg_check = params['disable_gpg_check']
|
|
|
|
disable_gpg_check = params['disable_gpg_check']
|
|
|
|
disable_recommends = params['disable_recommends']
|
|
|
|
disable_recommends = params['disable_recommends']
|
|
|
|
|
|
|
|
|
|
|
@ -272,11 +280,11 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
# Perform requested action
|
|
|
|
# Perform requested action
|
|
|
|
if state in ['installed', 'present']:
|
|
|
|
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']:
|
|
|
|
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':
|
|
|
|
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 rc != 0:
|
|
|
|
if stderr:
|
|
|
|
if stderr:
|
|
|
|