Add OpenBSD pkg_add(1) snapshot support (#965)

* Add OpenBSD pkg_add(1) snapshot support

* Fix documentation syntax

Co-authored-by: Felix Fontein <felix@fontein.de>

* Bump version_added

Co-authored-by: Felix Fontein <felix@fontein.de>

* zap one trailing whitespace

The first trailing whitespace is necessary otherwise we cal pkg_add(1)
with '-Im-Dsnap' which is invalid.

* Check build flag in package_present()

* zap one trailing whitespace

The first trailing whitespace is necessary otherwise we cal pkg_add(1)
with '-Im-Dsnap' which is invalid.

* check snapshot/build combination a little earlier

* Update "Force" documentation

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Bump version tgo 1.3.0

Co-authored-by: Felix Fontein <felix@fontein.de>

* Add a changelog fragment.

* Update plugins/modules/packaging/os/openbsd_pkg.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Add: mutually exclusiv hint for "build" and add mutually_exclusive

* Re-add build=%s check

Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
Rafael Sadowski 2020-11-13 06:33:13 +01:00 committed by GitHub
parent 4ea632b4e5
commit ef49950b96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
minor_changes:
- openbsd_pkg - added ``snapshot`` option (https://github.com/ansible-collections/community.general/pull/965).

View file

@ -40,8 +40,16 @@ options:
a binary. Requires that the port source tree is already installed. a binary. Requires that the port source tree is already installed.
Automatically builds and installs the 'sqlports' package, if it is Automatically builds and installs the 'sqlports' package, if it is
not already installed. not already installed.
- Mutually exclusive with I(snapshot).
type: bool type: bool
default: no default: no
snapshot:
description:
- Force C(%c) and C(%m) to expand to C(snapshots), even on a release kernel.
- Mutually exclusive with I(build).
type: bool
default: no
version_added: 1.3.0
ports_dir: ports_dir:
description: description:
- When used in combination with the C(build) option, allows overriding - When used in combination with the C(build) option, allows overriding
@ -197,6 +205,9 @@ def package_present(names, pkg_spec, module):
else: else:
install_cmd = 'pkg_add -Im' install_cmd = 'pkg_add -Im'
if module.params['snapshot'] is True:
install_cmd += ' -Dsnap'
if pkg_spec[name]['installed_state'] is False: if pkg_spec[name]['installed_state'] is False:
# Attempt to install the package # Attempt to install the package
@ -269,6 +280,9 @@ def package_latest(names, pkg_spec, module):
if module.params['quick']: if module.params['quick']:
upgrade_cmd += 'q' upgrade_cmd += 'q'
if module.params['snapshot']:
upgrade_cmd += ' -Dsnap'
for name in names: for name in names:
if pkg_spec[name]['installed_state'] is True: if pkg_spec[name]['installed_state'] is True:
@ -489,6 +503,9 @@ def upgrade_packages(pkg_spec, module):
else: else:
upgrade_cmd = 'pkg_add -Imu' upgrade_cmd = 'pkg_add -Imu'
if module.params['snapshot']:
upgrade_cmd += ' -Dsnap'
# Create a minimal pkg_spec entry for '*' to store return values. # Create a minimal pkg_spec entry for '*' to store return values.
pkg_spec['*'] = {} pkg_spec['*'] = {}
@ -520,10 +537,12 @@ def main():
name=dict(type='list', elements='str', required=True), name=dict(type='list', elements='str', required=True),
state=dict(type='str', default='present', choices=['absent', 'installed', 'latest', 'present', 'removed']), state=dict(type='str', default='present', choices=['absent', 'installed', 'latest', 'present', 'removed']),
build=dict(type='bool', default=False), build=dict(type='bool', default=False),
snapshot=dict(type='bool', default=False),
ports_dir=dict(type='path', default='/usr/ports'), ports_dir=dict(type='path', default='/usr/ports'),
quick=dict(type='bool', default=False), quick=dict(type='bool', default=False),
clean=dict(type='bool', default=False), clean=dict(type='bool', default=False),
), ),
mutually_exclusive=[['snapshot', 'build']],
supports_check_mode=True supports_check_mode=True
) )