From 788dc4bc2338347b25c919d8bafba42c8009127c Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 20 Oct 2020 07:31:20 +0200 Subject: [PATCH] redis: use regexp to check if the value matches expected form (#1079) (#1129) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use regexp to check if the value matches expected form regexp should match values like: - 1B - 10MB - 10mb * Added changelog entry * Update changelogs/fragments/1079-redis-use-regexp-to-check-if-the-value-matches-expected-form.yaml Co-authored-by: Amin Vakil Co-authored-by: Amin Vakil (cherry picked from commit bcfd6488552cd57093471a50b34b72c6a4b65c80) Co-authored-by: Robbert Müller --- ...-regexp-to-check-if-the-value-matches-expected-form.yaml | 2 ++ plugins/modules/database/misc/redis.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/1079-redis-use-regexp-to-check-if-the-value-matches-expected-form.yaml diff --git a/changelogs/fragments/1079-redis-use-regexp-to-check-if-the-value-matches-expected-form.yaml b/changelogs/fragments/1079-redis-use-regexp-to-check-if-the-value-matches-expected-form.yaml new file mode 100644 index 0000000000..27d01de91d --- /dev/null +++ b/changelogs/fragments/1079-redis-use-regexp-to-check-if-the-value-matches-expected-form.yaml @@ -0,0 +1,2 @@ +bugfixes: + - redis - fixes parsing of config values which should not be converted to bytes (https://github.com/ansible-collections/community.general/pull/1079). diff --git a/plugins/modules/database/misc/redis.py b/plugins/modules/database/misc/redis.py index 60ac88a0d5..8207e184a2 100644 --- a/plugins/modules/database/misc/redis.py +++ b/plugins/modules/database/misc/redis.py @@ -131,6 +131,7 @@ else: from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.common.text.formatters import human_to_bytes from ansible.module_utils._text import to_native +import re # Redis module specific support methods. @@ -277,7 +278,10 @@ def main(): name = module.params['name'] try: # try to parse the value as if it were the memory size - value = str(human_to_bytes(module.params['value'].upper())) + if re.match(r'^\s*(\d*\.?\d*)\s*([A-Za-z]+)?\s*$', module.params['value'].upper()): + value = str(human_to_bytes(module.params['value'].upper())) + else: + value = module.params['value'] except ValueError: value = module.params['value']