mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-09-26 03:23:22 -07:00
rabbitmq_plugin for Windows (#28017)
* Fixes #28016: rabbitmq_plugin for Windows * Disable documentation check for rabbitmq_plugin.ps1 * Renamed rabbitmq_plugin -> win_rabbitmq_plugin * Fixed the documentation after review * Fixed 'RETURN' section * Fixed docs for original module * Added dots to original module docs.
This commit is contained in:
parent
3631163329
commit
6058cb736d
3 changed files with 205 additions and 16 deletions
|
@ -16,46 +16,55 @@ ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: rabbitmq_plugin
|
module: rabbitmq_plugin
|
||||||
short_description: Adds or removes plugins to RabbitMQ
|
short_description: Manage RabbitMQ plugins
|
||||||
description:
|
description:
|
||||||
- Enables or disables RabbitMQ plugins
|
- Manage RabbitMQ plugins.
|
||||||
version_added: "1.1"
|
version_added: "1.1"
|
||||||
author: '"Chris Hoffman (@chrishoffman)"'
|
author:
|
||||||
|
- Chris Hoffman (@chrishoffman)
|
||||||
options:
|
options:
|
||||||
names:
|
names:
|
||||||
description:
|
description:
|
||||||
- Comma-separated list of plugin names
|
- Comma-separated list of plugin names.
|
||||||
required: true
|
required: true
|
||||||
default: null
|
|
||||||
aliases: [name]
|
aliases: [name]
|
||||||
new_only:
|
new_only:
|
||||||
description:
|
description:
|
||||||
- Only enable missing plugins
|
- Only enable missing plugins.
|
||||||
- Does not disable plugins that are not in the names list
|
- Does not disable plugins that are not in the names list.
|
||||||
required: false
|
type: bool
|
||||||
default: "no"
|
default: "no"
|
||||||
choices: [ "yes", "no" ]
|
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Specify if plugins are to be enabled or disabled
|
- Specify if plugins are to be enabled or disabled.
|
||||||
required: false
|
|
||||||
default: enabled
|
default: enabled
|
||||||
choices: [enabled, disabled]
|
choices: [enabled, disabled]
|
||||||
prefix:
|
prefix:
|
||||||
description:
|
description:
|
||||||
- Specify a custom install prefix to a Rabbit
|
- Specify a custom install prefix to a Rabbit.
|
||||||
required: false
|
|
||||||
version_added: "1.3"
|
version_added: "1.3"
|
||||||
default: null
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Enables the rabbitmq_management plugin
|
- name: Enables the rabbitmq_management plugin
|
||||||
- rabbitmq_plugin:
|
rabbitmq_plugin:
|
||||||
names: rabbitmq_management
|
names: rabbitmq_management
|
||||||
state: enabled
|
state: enabled
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
enabled:
|
||||||
|
description: list of plugins enabled during task run
|
||||||
|
returned: always
|
||||||
|
type: list
|
||||||
|
sample: ["rabbitmq_management"]
|
||||||
|
disabled:
|
||||||
|
description: list of plugins disabled during task run
|
||||||
|
returned: always
|
||||||
|
type: list
|
||||||
|
sample: ["rabbitmq_management"]
|
||||||
|
'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
121
lib/ansible/modules/windows/win_rabbitmq_plugin.ps1
Normal file
121
lib/ansible/modules/windows/win_rabbitmq_plugin.ps1
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
#!powershell
|
||||||
|
# Copyright (c) 2017 Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
|
function Get-EnabledPlugins($rabbitmq_plugins_cmd)
|
||||||
|
{
|
||||||
|
$list_plugins_cmd = "$rabbitmq_plugins_cmd list -E -m"
|
||||||
|
try {
|
||||||
|
$enabled_plugins = @(Invoke-Expression "& $list_plugins_cmd" | Where { $_ })
|
||||||
|
return ,$enabled_plugins
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Fail-Json -obj $result -message "Can't execute `"$($list_plugins_cmd)`": $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Enable-Plugin($rabbitmq_plugins_cmd, $plugin_name)
|
||||||
|
{
|
||||||
|
$enable_plugin_cmd = "$rabbitmq_plugins_cmd enable $plugin_name"
|
||||||
|
try {
|
||||||
|
Invoke-Expression "& $enable_plugin_cmd"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Fail-Json -obj $result -message "Can't execute `"$($enable_plugin_cmd)`": $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Disable-Plugin($rabbitmq_plugins_cmd, $plugin_name)
|
||||||
|
{
|
||||||
|
$enable_plugin_cmd = "$rabbitmq_plugins_cmd disable $plugin_name"
|
||||||
|
try {
|
||||||
|
Invoke-Expression "& $enable_plugin_cmd"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Fail-Json -obj $result -message "Can't execute `"$($enable_plugin_cmd)`": $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
$result = @{
|
||||||
|
changed = $false
|
||||||
|
enabled = @()
|
||||||
|
disabled = @()
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = Parse-Args $args -supports_check_mode $true;
|
||||||
|
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
|
||||||
|
$diff_support = Get-AnsibleParam -obj $params -name "_ansible_diff" -type "bool" -default $false
|
||||||
|
|
||||||
|
$names = Get-AnsibleParam -obj $params -name "names" -type "str" -failifempty $true -aliases "name"
|
||||||
|
$new_only = Get-AnsibleParam -obj $params -name "new_only" -type "bool" -default $false
|
||||||
|
$state = Get-AnsibleParam -obj $params -name "state" -type "str" -default "enabled" -validateset "enabled","disabled"
|
||||||
|
$prefix = Get-AnsibleParam -obj $params -name "prefix" -type "str"
|
||||||
|
|
||||||
|
if ($diff_support) {
|
||||||
|
$result.diff = @{}
|
||||||
|
$result.diff.prepared = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
$plugins = $names.Split(",")
|
||||||
|
|
||||||
|
if ($prefix) {
|
||||||
|
if (Test-Path (Join-Path -Path $prefix -ChildPath 'bin')) {
|
||||||
|
$rabbitmq_bin_path = Join-Path -Path $prefix -ChildPath 'bin'
|
||||||
|
} elseif (Test-Path (Join-Path -Path $prefix -ChildPath 'sbin')) {
|
||||||
|
$rabbitmq_bin_path = Join-Path -Path $prefix -ChildPath 'sbin'
|
||||||
|
} else {
|
||||||
|
Fail-Json -obj $result -message "No binary folder in prefix `"$($prefix)`""
|
||||||
|
}
|
||||||
|
$rabbitmq_plugins_cmd = "'$(Join-Path -Path $rabbitmq_bin_path -ChildPath "rabbitmq-plugins")'"
|
||||||
|
} else {
|
||||||
|
$rabbitmq_plugins_cmd = "rabbitmq-plugins"
|
||||||
|
}
|
||||||
|
|
||||||
|
$enabled_plugins = Get-EnabledPlugins -rabbitmq_plugins_cmd $rabbitmq_plugins_cmd
|
||||||
|
|
||||||
|
if ($state -eq "enabled") {
|
||||||
|
$plugins_to_enable = $plugins | ?{-not ($enabled_plugins -contains $_)}
|
||||||
|
foreach ($plugin in $plugins_to_enable) {
|
||||||
|
if (-not $check_mode) {
|
||||||
|
Enable-Plugin -rabbitmq_plugins_cmd $rabbitmq_plugins_cmd -plugin_name $plugin
|
||||||
|
}
|
||||||
|
if ($diff_support) {
|
||||||
|
$result.diff.prepared += "+[$plugin]`n"
|
||||||
|
}
|
||||||
|
$result.enabled += $plugin
|
||||||
|
$result.changed = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $new_only) {
|
||||||
|
$plugins_to_disable = $enabled_plugins | ?{-not ($plugins -contains $_)}
|
||||||
|
foreach ($plugin in $plugins_to_disable) {
|
||||||
|
if (-not $check_mode) {
|
||||||
|
Disable-Plugin -rabbitmq_plugins_cmd $rabbitmq_plugins_cmd -plugin_name $plugin
|
||||||
|
}
|
||||||
|
if ($diff_support) {
|
||||||
|
$result.diff.prepared += "-[$plugin]`n"
|
||||||
|
}
|
||||||
|
$result.disabled += $plugin
|
||||||
|
$result.changed = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$plugins_to_disable = $enabled_plugins | ?{$plugins -contains $_}
|
||||||
|
foreach ($plugin in $plugins_to_disable) {
|
||||||
|
if (-not $check_mode) {
|
||||||
|
Disable-Plugin -rabbitmq_plugins_cmd $rabbitmq_plugins_cmd -plugin_name $plugin
|
||||||
|
}
|
||||||
|
if ($diff_support) {
|
||||||
|
$result.diff.prepared += "-[$plugin]`n"
|
||||||
|
}
|
||||||
|
$result.disabled += $plugin
|
||||||
|
$result.changed = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Exit-Json $result
|
59
lib/ansible/modules/windows/win_rabbitmq_plugin.py
Normal file
59
lib/ansible/modules/windows/win_rabbitmq_plugin.py
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# Copyright (c) 2017 Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
|
'status': ['preview'],
|
||||||
|
'supported_by': 'community'}
|
||||||
|
|
||||||
|
|
||||||
|
DOCUMENTATION = r'''
|
||||||
|
---
|
||||||
|
module: win_rabbitmq_plugin
|
||||||
|
short_description: Manage RabbitMQ plugins
|
||||||
|
description:
|
||||||
|
- Manage RabbitMQ plugins.
|
||||||
|
version_added: "2.4"
|
||||||
|
author:
|
||||||
|
- Artem Zinenko (@ar7z1)
|
||||||
|
options:
|
||||||
|
names:
|
||||||
|
description:
|
||||||
|
- Comma-separated list of plugin names.
|
||||||
|
required: true
|
||||||
|
aliases: [name]
|
||||||
|
new_only:
|
||||||
|
description:
|
||||||
|
- Only enable missing plugins.
|
||||||
|
- Does not disable plugins that are not in the names list.
|
||||||
|
type: bool
|
||||||
|
default: "no"
|
||||||
|
state:
|
||||||
|
description:
|
||||||
|
- Specify if plugins are to be enabled or disabled.
|
||||||
|
default: enabled
|
||||||
|
choices: [enabled, disabled]
|
||||||
|
prefix:
|
||||||
|
description:
|
||||||
|
- Specify a custom install prefix to a Rabbit.
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = r'''
|
||||||
|
- name: Enables the rabbitmq_management plugin
|
||||||
|
win_rabbitmq_plugin:
|
||||||
|
names: rabbitmq_management
|
||||||
|
state: enabled
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = r'''
|
||||||
|
enabled:
|
||||||
|
description: list of plugins enabled during task run
|
||||||
|
returned: always
|
||||||
|
type: list
|
||||||
|
sample: ["rabbitmq_management"]
|
||||||
|
disabled:
|
||||||
|
description: list of plugins disabled during task run
|
||||||
|
returned: always
|
||||||
|
type: list
|
||||||
|
sample: ["rabbitmq_management"]
|
||||||
|
'''
|
Loading…
Add table
Add a link
Reference in a new issue