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
31e5e81f
Commit
31e5e81f
authored
Feb 10, 2013
by
Chris Hoffman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Standarizing module in line with other rabbitmq modules, adding support for setting tracing
parent
b79d7a60
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
34 deletions
+75
-34
library/rabbitmq_vhost
+75
-34
No files found.
library/rabbitmq_vhost
View file @
31e5e81f
...
@@ -31,62 +31,103 @@ options:
...
@@ -31,62 +31,103 @@ options:
- The name of the vhost to manage
- The name of the vhost to manage
required: true
required: true
default: null
default: null
tracing:
description:
Enable/disable tracing for a vhost
default: no
choices: [yes, no]
state:
state:
description:
description:
- The state of vhost
- The state of vhost
required: true
default: present
default: null
choices: [present, absent]
choices: [ "present", "absent" ]
examples:
examples:
- code:
"rabbitmq_vhost: name=/test state=present"
- code:
'rabbitmq_vhost: name=/test state=present'
description: Ensure that the vhost /test exists.
description: Ensure that the vhost /test exists.
author: Matt Cordial
author: Matt Cordial
'''
'''
class
RabbitMqVhost
(
object
):
def
__init__
(
self
,
module
,
name
,
tracing
):
self
.
module
=
module
self
.
name
=
name
self
.
tracing
=
tracing
self
.
_tracing
=
False
self
.
_rabbitmqctl
=
module
.
get_bin_path
(
'rabbitmqctl'
,
True
)
def
_exec
(
self
,
args
,
run_in_check_mode
=
False
):
if
not
self
.
module
.
check_mode
or
(
self
.
module
.
check_mode
and
run_in_check_mode
):
cmd
=
[
self
.
_rabbitmqctl
,
'-q'
]
rc
,
out
,
err
=
self
.
module
.
run_command
(
cmd
+
args
,
check_rc
=
True
)
return
out
.
splitlines
()
return
list
()
def
get
(
self
):
vhosts
=
self
.
_exec
([
'list_vhosts'
,
'name'
,
'tracing'
],
True
)
for
vhost
in
vhosts
:
name
,
tracing
=
vhost
.
split
(
'
\t
'
)
if
name
==
self
.
name
:
self
.
_tracing
=
self
.
module
.
boolean
(
tracing
)
return
True
return
False
def
add
(
self
):
return
self
.
_exec
([
'add_vhost'
,
self
.
name
])
def
delete
(
self
):
return
self
.
_exec
([
'delete_vhost'
,
self
.
name
])
def
set_tracing
(
self
):
if
self
.
tracing
!=
self
.
_tracing
:
if
self
.
tracing
:
self
.
_enable_tracing
()
else
:
self
.
_disable_tracing
()
return
True
return
False
def
_enable_tracing
(
self
):
return
self
.
_exec
([
'trace_on'
,
'-p'
,
self
.
name
])
def
_disable_tracing
(
self
):
return
self
.
_exec
([
'trace_off'
,
'-p'
,
self
.
name
])
def
main
():
def
main
():
arg_spec
=
dict
(
arg_spec
=
dict
(
name
=
dict
(
required
=
True
),
name
=
dict
(
required
=
True
),
state
=
dict
(
required
=
False
,
choices
=
[
'present'
,
'absent'
])
tracing
=
dict
(
default
=
'off'
,
choices
=
BOOLEANS
),
state
=
dict
(
default
=
'present'
,
choices
=
[
'present'
,
'absent'
])
)
)
module
=
AnsibleModule
(
argument_spec
=
arg_spec
)
module
=
AnsibleModule
(
argument_spec
=
arg_spec
,
supports_check_mode
=
True
)
name
=
module
.
params
[
'name'
]
name
=
module
.
params
[
'name'
]
tracing
=
module
.
boolean
(
module
.
params
[
'tracing'
])
state
=
module
.
params
[
'state'
]
state
=
module
.
params
[
'state'
]
RABBITMQCTL
=
module
.
get_bin_path
(
'rabbitmqctl'
,
True
)
rabbitmq_vhost
=
RabbitMqVhost
(
module
,
name
,
tracing
)
present
=
False
rc
,
out
,
err
=
module
.
run_command
(
'
%
s list_vhosts'
%
RABBITMQCTL
)
for
line
in
out
.
splitlines
():
if
line
.
strip
()
==
name
:
present
=
True
break
if
state
==
'present'
and
present
:
changed
=
False
module
.
exit_json
(
changed
=
False
,
name
=
name
,
state
=
state
)
if
rabbitmq_vhost
.
get
():
if
state
==
'absent'
:
if
state
==
'present'
and
not
present
:
rabbitmq_vhost
.
delete
()
rc
,
out
,
err
=
module
.
run_command
(
'
%
s add_vhost
%
s'
%
(
RABBITMQCTL
,
name
))
changed
=
True
if
'...done'
in
out
:
module
.
exit_json
(
changed
=
True
,
name
=
name
,
state
=
state
)
else
:
else
:
module
.
fail_json
(
msg
=
out
,
name
=
name
,
state
=
state
)
if
rabbitmq_vhost
.
set_tracing
():
changed
=
True
if
state
==
'absent'
and
not
present
:
elif
state
==
'present'
:
module
.
exit_json
(
changed
=
False
,
name
=
name
,
state
=
state
)
rabbitmq_vhost
.
add
()
rabbitmq_vhost
.
set_tracing
()
changed
=
True
if
state
==
'absent'
and
present
:
module
.
exit_json
(
changed
=
changed
,
name
=
name
,
state
=
state
)
rc
,
out
,
err
=
module
.
run_command
(
'
%
s delete_vhost
%
s'
%
(
RABBITMQCTL
,
name
))
if
'...done'
in
out
:
module
.
exit_json
(
changed
=
True
,
name
=
name
,
state
=
state
)
else
:
module
.
fail_json
(
msg
=
out
,
name
=
name
,
state
=
state
)
module
.
exit_json
(
changed
=
False
,
name
=
name
,
state
=
state
)
# 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>>
main
()
main
()
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