diff options
author | Milan Ilic <35260522+ilicmilan@users.noreply.github.com> | 2020-02-15 14:15:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-15 13:15:12 +0000 |
commit | 717b7fee9f369d5b588c1e82cd2c80300c4e8caf (patch) | |
tree | b1760afa73cd66be699b2a312a42bbd4c39a913a /lib/ansible/modules/database | |
parent | 24ce97a49b0a98bec777f77d34241bb51c12e648 (diff) | |
download | ansible-717b7fee9f369d5b588c1e82cd2c80300c4e8caf.tar.gz |
Update redis module to support memory size units (#66975)
Diffstat (limited to 'lib/ansible/modules/database')
-rw-r--r-- | lib/ansible/modules/database/misc/redis.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/ansible/modules/database/misc/redis.py b/lib/ansible/modules/database/misc/redis.py index 0a27c4e1b1..475f072892 100644 --- a/lib/ansible/modules/database/misc/redis.py +++ b/lib/ansible/modules/database/misc/redis.py @@ -64,10 +64,11 @@ options: version_added: 1.6 value: description: - - A redis config value. + - A redis config value. When memory size is needed, it is possible + to specify it in the usal form of 1KB, 2M, 400MB where the base is 1024. + Units are case insensitive i.e. 1m = 1mb = 1M = 1MB. version_added: 1.6 - notes: - Requires the redis-py Python package on the remote host. You can install it with pip (pip install redis) or with a package manager. @@ -108,6 +109,12 @@ EXAMPLES = ''' name: maxclients value: 10000 +- name: Configure local redis maxmemory to 4GB + redis: + command: config + name: maxmemory + value: 4GB + - name: Configure local redis to have lua time limit of 100 ms redis: command: config @@ -127,6 +134,7 @@ else: redis_found = True 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 @@ -272,7 +280,11 @@ def main(): module.fail_json(msg="Unable to flush '%d' database" % db) elif command == 'config': name = module.params['name'] - value = module.params['value'] + + try: # try to parse the value as if it were the memory size + value = str(human_to_bytes(module.params['value'].upper())) + except ValueError: + value = module.params['value'] r = redis.StrictRedis(host=login_host, port=login_port, password=login_password) |