Server IP : 85.214.239.14 / Your IP : 18.191.233.251 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /lib/python3/dist-packages/ansible_collections/community/general/plugins/modules/ |
Upload File : |
#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2021, Andreas Botzner <andreas at botzner dot com> # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) # SPDX-License-Identifier: GPL-3.0-or-later from __future__ import absolute_import, division, print_function __metaclass__ = type DOCUMENTATION = ''' --- module: redis_data_info short_description: Get value of key in Redis database version_added: 3.7.0 description: - Get value of keys in Redis database. author: "Andreas Botzner (@paginabianca)" options: key: description: - Database key. type: str required: true extends_documentation_fragment: - community.general.redis - community.general.attributes - community.general.attributes.info_module seealso: - module: community.general.redis_data - module: community.general.redis_data_incr - module: community.general.redis_info - module: community.general.redis ''' EXAMPLES = ''' - name: Get key foo=bar from loalhost with no username community.general.redis_data_info: login_host: localhost login_password: supersecret key: foo - name: Get key foo=bar on redishost with custom ca-cert file community.general.redis_data_info: login_host: redishost login_password: supersecret login_user: somuser validate_certs: true ssl_ca_certs: /path/to/ca/certs key: foo ''' RETURN = ''' exists: description: If they key exists in the database. returned: on success type: bool value: description: Value key was set to. returned: if existing type: str sample: 'value_of_some_key' msg: description: A short message. returned: always type: str sample: 'Got key: foo with value: bar' ''' from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.general.plugins.module_utils.redis import ( fail_imports, redis_auth_argument_spec, RedisAnsible) def main(): redis_auth_args = redis_auth_argument_spec() module_args = dict( key=dict(type='str', required=True, no_log=False), ) module_args.update(redis_auth_args) module = AnsibleModule( argument_spec=module_args, supports_check_mode=True, ) fail_imports(module) redis = RedisAnsible(module) key = module.params['key'] result = {'changed': False} value = None try: value = redis.connection.get(key) except Exception as e: msg = 'Failed to get value of key "{0}" with exception: {1}'.format( key, str(e)) result['msg'] = msg module.fail_json(**result) if value is None: msg = 'Key "{0}" does not exist in database'.format(key) result['exists'] = False else: msg = 'Got key "{0}"'.format(key) result['value'] = value result['exists'] = True result['msg'] = msg module.exit_json(**result) if __name__ == '__main__': main()