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']