1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

redis: use regexp to check if the value matches expected form (#1079)

* 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 <info@aminvakil.com>

Co-authored-by: Amin Vakil <info@aminvakil.com>
This commit is contained in:
Robbert Müller 2020-10-20 07:04:42 +02:00 committed by GitHub
parent 6c1d014044
commit bcfd648855
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -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).

View file

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