From ef49950b96849ba8edcd74953a96a16cfd5d653e Mon Sep 17 00:00:00 2001 From: Rafael Sadowski Date: Fri, 13 Nov 2020 06:33:13 +0100 Subject: [PATCH] Add OpenBSD pkg_add(1) snapshot support (#965) * Add OpenBSD pkg_add(1) snapshot support * Fix documentation syntax Co-authored-by: Felix Fontein * Bump version_added Co-authored-by: Felix Fontein * 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 * Bump version tgo 1.3.0 Co-authored-by: Felix Fontein * Add a changelog fragment. * Update plugins/modules/packaging/os/openbsd_pkg.py Co-authored-by: Andrew Klychkov * Add: mutually exclusiv hint for "build" and add mutually_exclusive * Re-add build=%s check Co-authored-by: Felix Fontein Co-authored-by: Andrew Klychkov --- changelogs/fragments/openbsd_pkg.yml | 3 +++ plugins/modules/packaging/os/openbsd_pkg.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 changelogs/fragments/openbsd_pkg.yml diff --git a/changelogs/fragments/openbsd_pkg.yml b/changelogs/fragments/openbsd_pkg.yml new file mode 100644 index 0000000000..2daeb3d2ec --- /dev/null +++ b/changelogs/fragments/openbsd_pkg.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - openbsd_pkg - added ``snapshot`` option (https://github.com/ansible-collections/community.general/pull/965). diff --git a/plugins/modules/packaging/os/openbsd_pkg.py b/plugins/modules/packaging/os/openbsd_pkg.py index d2aff81c53..b9f4d577a4 100644 --- a/plugins/modules/packaging/os/openbsd_pkg.py +++ b/plugins/modules/packaging/os/openbsd_pkg.py @@ -40,8 +40,16 @@ options: a binary. Requires that the port source tree is already installed. Automatically builds and installs the 'sqlports' package, if it is not already installed. + - Mutually exclusive with I(snapshot). type: bool 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: description: - When used in combination with the C(build) option, allows overriding @@ -197,6 +205,9 @@ def package_present(names, pkg_spec, module): else: install_cmd = 'pkg_add -Im' + if module.params['snapshot'] is True: + install_cmd += ' -Dsnap' + if pkg_spec[name]['installed_state'] is False: # Attempt to install the package @@ -269,6 +280,9 @@ def package_latest(names, pkg_spec, module): if module.params['quick']: upgrade_cmd += 'q' + if module.params['snapshot']: + upgrade_cmd += ' -Dsnap' + for name in names: if pkg_spec[name]['installed_state'] is True: @@ -489,6 +503,9 @@ def upgrade_packages(pkg_spec, module): else: upgrade_cmd = 'pkg_add -Imu' + if module.params['snapshot']: + upgrade_cmd += ' -Dsnap' + # Create a minimal pkg_spec entry for '*' to store return values. pkg_spec['*'] = {} @@ -520,10 +537,12 @@ def main(): name=dict(type='list', elements='str', required=True), state=dict(type='str', default='present', choices=['absent', 'installed', 'latest', 'present', 'removed']), build=dict(type='bool', default=False), + snapshot=dict(type='bool', default=False), ports_dir=dict(type='path', default='/usr/ports'), quick=dict(type='bool', default=False), clean=dict(type='bool', default=False), ), + mutually_exclusive=[['snapshot', 'build']], supports_check_mode=True )