From eb410a99876c22e841bf7dfb007e8345f4094b9a Mon Sep 17 00:00:00 2001 From: Florian Pracht Date: Fri, 30 Nov 2018 03:53:53 +0100 Subject: [PATCH] Run patch command with --check option instead of --dry-run to support older BSDs (#42168) --- lib/ansible/modules/files/patch.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/files/patch.py b/lib/ansible/modules/files/patch.py index e1534ef257..a279a3940a 100644 --- a/lib/ansible/modules/files/patch.py +++ b/lib/ansible/modules/files/patch.py @@ -100,7 +100,7 @@ EXAMPLES = r''' import os from traceback import format_exc -from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.basic import AnsibleModule, get_platform from ansible.module_utils._text import to_native @@ -108,10 +108,19 @@ class PatchError(Exception): pass +def add_dry_run_option(opts): + # Older versions of FreeBSD, OpenBSD and NetBSD support the --check option only. + if get_platform().lower() in ['openbsd', 'netbsd', 'freebsd']: + opts.append('--check') + else: + opts.append('--dry-run') + + def is_already_applied(patch_func, patch_file, basedir, dest_file=None, binary=False, strip=0, state='present'): - opts = ['--quiet', '--forward', '--dry-run', + opts = ['--quiet', '--forward', "--strip=%s" % strip, "--directory='%s'" % basedir, "--input='%s'" % patch_file] + add_dry_run_option(opts) if binary: opts.append('--binary') if dest_file: @@ -128,7 +137,7 @@ def apply_patch(patch_func, patch_file, basedir, dest_file=None, binary=False, s "--strip=%s" % strip, "--directory='%s'" % basedir, "--input='%s'" % patch_file] if dry_run: - opts.append('--dry-run') + add_dry_run_option(opts) if binary: opts.append('--binary') if dest_file: