diff options
author | Florian Pracht <florian.pracht@fpr8.de> | 2018-11-30 03:53:53 +0100 |
---|---|---|
committer | Brian Coca <bcoca@users.noreply.github.com> | 2018-11-29 21:53:53 -0500 |
commit | eb410a99876c22e841bf7dfb007e8345f4094b9a (patch) | |
tree | 8144d2d5ded20bbcc46a4a23072f7bd806e0c705 | |
parent | bc481c25006912cedf2f9f1bc07e18fa3cb2eb5e (diff) | |
download | ansible-eb410a99876c22e841bf7dfb007e8345f4094b9a.tar.gz |
Run patch command with --check option instead of --dry-run to support older BSDs (#42168)
-rw-r--r-- | lib/ansible/modules/files/patch.py | 15 |
1 files 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: |