Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
b0639b16
Commit
b0639b16
authored
Mar 19, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'devel' of
git://github.com/mleventi/ansible
into devel
parents
f2d9e064
07a388e5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
3 deletions
+49
-3
library/database/redis
+49
-3
No files found.
library/database/redis
View file @
b0639b16
...
@@ -22,8 +22,9 @@ module: redis
...
@@ -22,8 +22,9 @@ module: redis
short_description: Various redis commands, slave and flush
short_description: Various redis commands, slave and flush
description:
description:
- Unified utility to interact with redis instances.
- Unified utility to interact with redis instances.
'slave' Sets a redis instance in slave or master mode.
'slave'
Sets a redis instance in slave or master mode.
'flush' Flushes all the instance or a specified db.
'flush' Flushes all the instance or a specified db.
'config' Ensures a configuration setting on an instance.
version_added: "1.3"
version_added: "1.3"
options:
options:
command:
command:
...
@@ -31,7 +32,7 @@ options:
...
@@ -31,7 +32,7 @@ options:
- The selected redis command
- The selected redis command
required: true
required: true
default: null
default: null
choices: [ "slave", "flush" ]
choices: [ "slave", "flush"
, "config"
]
login_password:
login_password:
description:
description:
- The password used to authenticate with (usually not used)
- The password used to authenticate with (usually not used)
...
@@ -75,6 +76,16 @@ options:
...
@@ -75,6 +76,16 @@ options:
required: false
required: false
default: all
default: all
choices: [ "all", "db" ]
choices: [ "all", "db" ]
name:
description:
- A redis config key.
required: false
default: null
value:
description:
- A redis config value.
required: false
default: null
notes:
notes:
...
@@ -100,6 +111,12 @@ EXAMPLES = '''
...
@@ -100,6 +111,12 @@ EXAMPLES = '''
# Flush only one db in a redis instance
# Flush only one db in a redis instance
- redis: command=flush db=1 flush_mode=db
- redis: command=flush db=1 flush_mode=db
# Configure local redis to have 10000 max clients
- redis: command=config name=maxclients value=10000
# Configure local redis to have lua time limit of 100 ms
- redis: command=config name=lua-time-limit value=100
'''
'''
try
:
try
:
...
@@ -146,7 +163,7 @@ def flush(client, db=None):
...
@@ -146,7 +163,7 @@ def flush(client, db=None):
def
main
():
def
main
():
module
=
AnsibleModule
(
module
=
AnsibleModule
(
argument_spec
=
dict
(
argument_spec
=
dict
(
command
=
dict
(
default
=
None
,
choices
=
[
'slave'
,
'flush'
]),
command
=
dict
(
default
=
None
,
choices
=
[
'slave'
,
'flush'
,
'config'
]),
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'
),
...
@@ -155,6 +172,8 @@ def main():
...
@@ -155,6 +172,8 @@ def main():
slave_mode
=
dict
(
default
=
'slave'
,
choices
=
[
'master'
,
'slave'
]),
slave_mode
=
dict
(
default
=
'slave'
,
choices
=
[
'master'
,
'slave'
]),
db
=
dict
(
default
=
None
),
db
=
dict
(
default
=
None
),
flush_mode
=
dict
(
default
=
'all'
,
choices
=
[
'all'
,
'db'
]),
flush_mode
=
dict
(
default
=
'all'
,
choices
=
[
'all'
,
'db'
]),
name
=
dict
(
default
=
None
),
value
=
dict
(
default
=
None
)
),
),
supports_check_mode
=
True
supports_check_mode
=
True
)
)
...
@@ -272,7 +291,34 @@ def main():
...
@@ -272,7 +291,34 @@ def main():
module
.
exit_json
(
changed
=
True
,
flushed
=
True
,
db
=
db
)
module
.
exit_json
(
changed
=
True
,
flushed
=
True
,
db
=
db
)
else
:
# Flush never fails :)
else
:
# Flush never fails :)
module
.
fail_json
(
msg
=
"Unable to flush '
%
d' database"
%
db
)
module
.
fail_json
(
msg
=
"Unable to flush '
%
d' database"
%
db
)
elif
command
==
'config'
:
name
=
module
.
params
[
'name'
]
value
=
module
.
params
[
'value'
]
r
=
redis
.
StrictRedis
(
host
=
login_host
,
port
=
login_port
,
password
=
login_password
)
try
:
r
.
ping
()
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"unable to connect to database:
%
s"
%
e
)
try
:
old_value
=
r
.
config_get
(
name
)[
name
]
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"unable to read config:
%
s"
%
e
)
changed
=
old_value
!=
value
if
module
.
check_mode
or
not
changed
:
module
.
exit_json
(
changed
=
changed
,
name
=
name
,
value
=
value
)
else
:
try
:
r
.
config_set
(
name
,
value
)
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"unable to write config:
%
s"
%
e
)
module
.
exit_json
(
changed
=
changed
,
name
=
name
,
value
=
value
)
else
:
else
:
module
.
fail_json
(
msg
=
'A valid command must be provided'
)
module
.
fail_json
(
msg
=
'A valid command must be provided'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment