mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-20 01:11:26 -07:00
* 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>
(cherry picked from commit bcfd648855
)
Co-authored-by: Robbert Müller <mjrider@users.noreply.github.com>
This commit is contained in:
parent
705118247d
commit
788dc4bc23
2 changed files with 7 additions and 1 deletions
|
@ -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).
|
|
@ -131,6 +131,7 @@ else:
|
||||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
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.common.text.formatters import human_to_bytes
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
# Redis module specific support methods.
|
# Redis module specific support methods.
|
||||||
|
@ -277,7 +278,10 @@ def main():
|
||||||
name = module.params['name']
|
name = module.params['name']
|
||||||
|
|
||||||
try: # try to parse the value as if it were the memory size
|
try: # try to parse the value as if it were the memory size
|
||||||
|
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()))
|
value = str(human_to_bytes(module.params['value'].upper()))
|
||||||
|
else:
|
||||||
|
value = module.params['value']
|
||||||
except ValueError:
|
except ValueError:
|
||||||
value = module.params['value']
|
value = module.params['value']
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue