From c24249c57d0ee166f064d6d1198819f87ed7225e Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 10 Feb 2016 11:23:49 -0500 Subject: [PATCH] made max diff size configurable --- examples/ansible.cfg | 4 ++++ lib/ansible/constants.py | 2 +- lib/ansible/plugins/action/__init__.py | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/ansible.cfg b/examples/ansible.cfg index c9dc7592a40..91ef70b77a5 100644 --- a/examples/ansible.cfg +++ b/examples/ansible.cfg @@ -198,6 +198,10 @@ # is used. This value must be an integer from 0 to 9. #var_compression_level = 9 +# This controls the cutoff point (in bytes) on --diff for files +# set to 0 for unlimited (RAM may suffer!). +#max_diff_size = 1048576 + [privilege_escalation] #become=True #become_method=sudo diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index bbb32c9cc35..6623b8f0c34 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -239,6 +239,7 @@ RETRY_FILES_ENABLED = get_config(p, DEFAULTS, 'retry_files_enabled', RETRY_FILES_SAVE_PATH = get_config(p, DEFAULTS, 'retry_files_save_path', 'ANSIBLE_RETRY_FILES_SAVE_PATH', None, ispath=True) DEFAULT_NULL_REPRESENTATION = get_config(p, DEFAULTS, 'null_representation', 'ANSIBLE_NULL_REPRESENTATION', None, isnone=True) DISPLAY_ARGS_TO_STDOUT = get_config(p, DEFAULTS, 'display_args_to_stdout', 'ANSIBLE_DISPLAY_ARGS_TO_STDOUT', False, boolean=True) +MAX_FILE_SIZE_FOR_DIFF = get_config(p, DEFAULTS, 'max_diff_size', 'ANSIBLE_MAX_DIFF_SIZE', 1024*1024, integer=True) # CONNECTION RELATED ANSIBLE_SSH_ARGS = get_config(p, 'ssh_connection', 'ssh_args', 'ANSIBLE_SSH_ARGS', '-o ControlMaster=auto -o ControlPersist=60s') @@ -298,6 +299,5 @@ DEFAULT_SUBSET = None DEFAULT_SU_PASS = None VAULT_VERSION_MIN = 1.0 VAULT_VERSION_MAX = 1.0 -MAX_FILE_SIZE_FOR_DIFF = 1*1024*1024 TREE_DIR = None LOCALHOST = frozenset(['127.0.0.1', 'localhost', '::1']) diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index 28eb6ffe6e7..093ddd058e5 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -615,7 +615,7 @@ class ActionBase(with_metaclass(ABCMeta, object)): diff['before'] = '' elif peek_result['appears_binary']: diff['dst_binary'] = 1 - elif peek_result['size'] > C.MAX_FILE_SIZE_FOR_DIFF: + elif C.MAX_FILE_SIZE_FOR_DIFF > 0 and peek_result['size'] > C.MAX_FILE_SIZE_FOR_DIFF: diff['dst_larger'] = C.MAX_FILE_SIZE_FOR_DIFF else: display.debug("Slurping the file %s" % source) @@ -631,7 +631,7 @@ class ActionBase(with_metaclass(ABCMeta, object)): if source_file: st = os.stat(source) - if st[stat.ST_SIZE] > C.MAX_FILE_SIZE_FOR_DIFF: + if C.MAX_FILE_SIZE_FOR_DIFF > 0 and st[stat.ST_SIZE] > C.MAX_FILE_SIZE_FOR_DIFF: diff['src_larger'] = C.MAX_FILE_SIZE_FOR_DIFF else: display.debug("Reading local copy of the file %s" % source) @@ -640,6 +640,7 @@ class ActionBase(with_metaclass(ABCMeta, object)): src_contents = src.read() except Exception as e: raise AnsibleError("Unexpected error while reading source (%s) for diff: %s " % (source, str(e))) + if "\x00" in src_contents: diff['src_binary'] = 1 else: