|
|
@ -26,9 +26,9 @@ description:
|
|
|
|
'flush' Flushes all the instance or ans specified db.
|
|
|
|
'flush' Flushes all the instance or ans specified db.
|
|
|
|
version_added: "1.3"
|
|
|
|
version_added: "1.3"
|
|
|
|
options:
|
|
|
|
options:
|
|
|
|
action:
|
|
|
|
command:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The selected redis action
|
|
|
|
- The selected redis command
|
|
|
|
required: true
|
|
|
|
required: true
|
|
|
|
default: null
|
|
|
|
default: null
|
|
|
|
choices: [ "slave", "flush" ]
|
|
|
|
choices: [ "slave", "flush" ]
|
|
|
@ -49,29 +49,29 @@ options:
|
|
|
|
default: 6379
|
|
|
|
default: 6379
|
|
|
|
master_host:
|
|
|
|
master_host:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The host of the master instance [slave action]
|
|
|
|
- The host of the master instance [slave command]
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
default: null
|
|
|
|
master_port:
|
|
|
|
master_port:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The port of the master instance [slave action]
|
|
|
|
- The port of the master instance [slave command]
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
default: null
|
|
|
|
slave_mode:
|
|
|
|
slave_mode:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- the mode of the redis instance [slave action]
|
|
|
|
- the mode of the redis instance [slave command]
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: slave
|
|
|
|
default: slave
|
|
|
|
choices: [ "master", "slave" ]
|
|
|
|
choices: [ "master", "slave" ]
|
|
|
|
db:
|
|
|
|
db:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The database to flush (used in db mode) [flush action]
|
|
|
|
- The database to flush (used in db mode) [flush command]
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
default: null
|
|
|
|
flush_mode:
|
|
|
|
flush_mode:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Type of flush (all the dbs in a redis instance or a specific one)
|
|
|
|
- Type of flush (all the dbs in a redis instance or a specific one)
|
|
|
|
[flush action]
|
|
|
|
[flush command]
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: all
|
|
|
|
default: all
|
|
|
|
choices: [ "all", "db" ]
|
|
|
|
choices: [ "all", "db" ]
|
|
|
@ -90,16 +90,16 @@ author: Xabier Larrakoetxea
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
EXAMPLES = '''
|
|
|
|
# Set local redis instance to be slave of melee.island on port 6377
|
|
|
|
# Set local redis instance to be slave of melee.island on port 6377
|
|
|
|
- redis: action=slave master_host=melee.island master_port=6377
|
|
|
|
- redis: command=slave master_host=melee.island master_port=6377
|
|
|
|
|
|
|
|
|
|
|
|
# Deactivate slave mode
|
|
|
|
# Deactivate slave mode
|
|
|
|
- redis: action=slave slave_mode=master
|
|
|
|
- redis: command=slave slave_mode=master
|
|
|
|
|
|
|
|
|
|
|
|
# Flush all the redis db
|
|
|
|
# Flush all the redis db
|
|
|
|
- redis: action=flush flush_mode=all
|
|
|
|
- redis: command=flush flush_mode=all
|
|
|
|
|
|
|
|
|
|
|
|
# Flush only one db in a redis instance
|
|
|
|
# Flush only one db in a redis instance
|
|
|
|
- redis: action=flush db=1 flush_mode=db
|
|
|
|
- redis: command=flush db=1 flush_mode=db
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -146,7 +146,7 @@ def flush(client, db=None):
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec = dict(
|
|
|
|
argument_spec = dict(
|
|
|
|
action=dict(default=None, choices=['slave', 'flush']),
|
|
|
|
command=dict(default=None, choices=['slave', 'flush']),
|
|
|
|
login_password=dict(default=None),
|
|
|
|
login_password=dict(default=None),
|
|
|
|
login_host=dict(default='localhost'),
|
|
|
|
login_host=dict(default='localhost'),
|
|
|
|
login_port=dict(default='6379'),
|
|
|
|
login_port=dict(default='6379'),
|
|
|
@ -165,10 +165,10 @@ def main():
|
|
|
|
login_password = module.params['login_password']
|
|
|
|
login_password = module.params['login_password']
|
|
|
|
login_host = module.params['login_host']
|
|
|
|
login_host = module.params['login_host']
|
|
|
|
login_port = int(module.params['login_port'])
|
|
|
|
login_port = int(module.params['login_port'])
|
|
|
|
action = module.params['action']
|
|
|
|
command = module.params['command']
|
|
|
|
|
|
|
|
|
|
|
|
# Slave Command section -----------
|
|
|
|
# Slave Command section -----------
|
|
|
|
if action == "slave":
|
|
|
|
if command == "slave":
|
|
|
|
master_host = module.params['master_host']
|
|
|
|
master_host = module.params['master_host']
|
|
|
|
master_port = module.params['master_port']
|
|
|
|
master_port = module.params['master_port']
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -213,7 +213,7 @@ def main():
|
|
|
|
module.exit_json(changed=False, mode=status)
|
|
|
|
module.exit_json(changed=False, mode=status)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# Do the stuff
|
|
|
|
# Do the stuff
|
|
|
|
# (Check Check_mode before actions so the actions aren't evaluated
|
|
|
|
# (Check Check_mode before commands so the commands aren't evaluated
|
|
|
|
# if not necesary)
|
|
|
|
# if not necesary)
|
|
|
|
if mode == "slave":
|
|
|
|
if mode == "slave":
|
|
|
|
if module.check_mode or\
|
|
|
|
if module.check_mode or\
|
|
|
@ -235,7 +235,7 @@ def main():
|
|
|
|
module.fail_json(msg='Unable to set master mode')
|
|
|
|
module.fail_json(msg='Unable to set master mode')
|
|
|
|
|
|
|
|
|
|
|
|
# flush Command section -----------
|
|
|
|
# flush Command section -----------
|
|
|
|
elif action == "flush":
|
|
|
|
elif command == "flush":
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
db = int(module.params['db'])
|
|
|
|
db = int(module.params['db'])
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
@ -259,7 +259,7 @@ def main():
|
|
|
|
module.fail_json(msg="unable to connect to database: %s" % e)
|
|
|
|
module.fail_json(msg="unable to connect to database: %s" % e)
|
|
|
|
|
|
|
|
|
|
|
|
# Do the stuff
|
|
|
|
# Do the stuff
|
|
|
|
# (Check Check_mode before actions so the actions aren't evaluated
|
|
|
|
# (Check Check_mode before commands so the commands aren't evaluated
|
|
|
|
# if not necesary)
|
|
|
|
# if not necesary)
|
|
|
|
if mode == "all":
|
|
|
|
if mode == "all":
|
|
|
|
if module.check_mode or flush(r):
|
|
|
|
if module.check_mode or flush(r):
|
|
|
@ -274,7 +274,7 @@ def main():
|
|
|
|
module.fail_json(msg="Unable to flush '%d' database" % db)
|
|
|
|
module.fail_json(msg="Unable to flush '%d' database" % db)
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
module.fail_json(msg='A valid action must be provided')
|
|
|
|
module.fail_json(msg='A valid command must be provided')
|
|
|
|
|
|
|
|
|
|
|
|
# this is magic, see lib/ansible/module_common.py
|
|
|
|
# this is magic, see lib/ansible/module_common.py
|
|
|
|
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
|
|
|
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
|
|
|