Repository: ansible/ansible

Issue:
rabbitmq_plugin doesn't work on Windows
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
rabbitmq_plugin

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (rabbitmq_plugin_for_windows 616d5ddc93) last updated 2017/08/09 10:10:19 (GMT +300)
  config file = /home/art/.ansible.cfg
  configured module search path = [u'/home/art/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/art/projects/github/ansible/lib/ansible
  executable location = /home/art/projects/github/ansible/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Manage any Windows.

##### SUMMARY
<!--- Explain the problem briefly -->
Can't install RabbitMQ plugins via `rabbitmq_plugin` module on Windows.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Ensure RabbitMQ installed
  win_chocolatey:
    name: rabbitmq

- name: Install Management Plugin
  rabbitmq_plugin:
    names: rabbitmq_management
    state: enabled
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
`rabbitmq_management` plugin successfully installed.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
I get the error:
<!--- Paste verbatim command output between quotes below -->
```
TASK [rabbitmq : Install Management Plugin] *************************************************************************************************************************************************************************************************
task path: /home/art/projects/ansible/roles/rabbitmq/tasks/windows.yml:7
Using module_utils file /home/art/projects/github/ansible/lib/ansible/module_utils/basic.py
Using module_utils file /home/art/projects/github/ansible/lib/ansible/module_utils/_text.py
Using module_utils file /home/art/projects/github/ansible/lib/ansible/module_utils/parsing/convert_bool.py
Using module_utils file /home/art/projects/github/ansible/lib/ansible/module_utils/parsing/__init__.py
Using module_utils file /home/art/projects/github/ansible/lib/ansible/module_utils/pycompat24.py
Using module_utils file /home/art/projects/github/ansible/lib/ansible/module_utils/six/__init__.py
Using module file /home/art/projects/github/ansible/lib/ansible/modules/messaging/rabbitmq_plugin.py
<host> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO host
EXEC (via pipeline wrapper)
 [WARNING]: FATAL ERROR DURING FILE TRANSFER: Traceback (most recent call last):   File "/home/art/projects/github/ansible/lib/ansible/plugins/connection/winrm.py", line 271, in _winrm_exec     self._winrm_send_input(self.protocol,
self.shell_id, command_id, data, eof=is_last)   File "/home/art/projects/github/ansible/lib/ansible/plugins/connection/winrm.py", line 251, in _winrm_send_input     protocol.send_message(xmltodict.unparse(rq))   File
"/home/art/.local/lib/python2.7/site-packages/winrm/protocol.py", line 207, in send_message     return self.transport.send_message(message)   File "/home/art/.local/lib/python2.7/site-packages/winrm/transport.py", line 202, in
send_message     raise WinRMTransportError('http', error_message) WinRMTransportError: (u'http', u'Bad HTTP response returned from server. Code 500')
```

rabbitmq_plugin doesn't work on Windows
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
rabbitmq_plugin

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (rabbitmq_plugin_for_windows 616d5ddc93) last updated 2017/08/09 10:10:19 (GMT +300)
  config file = /home/art/.ansible.cfg
  configured module search path = [u'/home/art/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/art/projects/github/ansible/lib/ansible
  executable location = /home/art/projects/github/ansible/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Manage any Windows.

##### SUMMARY
<!--- Explain the problem briefly -->
Can't install RabbitMQ plugins via `rabbitmq_plugin` module on Windows.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Ensure RabbitMQ installed
  win_chocolatey:
    name: rabbitmq

- name: Install Management Plugin
  rabbitmq_plugin:
    names: rabbitmq_management
    state: enabled
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
`rabbitmq_management` plugin successfully installed.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
I get the error:
<!--- Paste verbatim command output between quotes below -->
```
TASK [rabbitmq : Install Management Plugin] *************************************************************************************************************************************************************************************************
task path: /home/art/projects/ansible/roles/rabbitmq/tasks/windows.yml:7
Using module_utils file /home/art/projects/github/ansible/lib/ansible/module_utils/basic.py
Using module_utils file /home/art/projects/github/ansible/lib/ansible/module_utils/_text.py
Using module_utils file /home/art/projects/github/ansible/lib/ansible/module_utils/parsing/convert_bool.py
Using module_utils file /home/art/projects/github/ansible/lib/ansible/module_utils/parsing/__init__.py
Using module_utils file /home/art/projects/github/ansible/lib/ansible/module_utils/pycompat24.py
Using module_utils file /home/art/projects/github/ansible/lib/ansible/module_utils/six/__init__.py
Using module file /home/art/projects/github/ansible/lib/ansible/modules/messaging/rabbitmq_plugin.py
<host> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO host
EXEC (via pipeline wrapper)
 [WARNING]: FATAL ERROR DURING FILE TRANSFER: Traceback (most recent call last):   File "/home/art/projects/github/ansible/lib/ansible/plugins/connection/winrm.py", line 271, in _winrm_exec     self._winrm_send_input(self.protocol,
self.shell_id, command_id, data, eof=is_last)   File "/home/art/projects/github/ansible/lib/ansible/plugins/connection/winrm.py", line 251, in _winrm_send_input     protocol.send_message(xmltodict.unparse(rq))   File
"/home/art/.local/lib/python2.7/site-packages/winrm/protocol.py", line 207, in send_message     return self.transport.send_message(message)   File "/home/art/.local/lib/python2.7/site-packages/winrm/transport.py", line 202, in
send_message     raise WinRMTransportError('http', error_message) WinRMTransportError: (u'http', u'Bad HTTP response returned from server. Code 500')
```



Discussion:
I'll create a PR soon.
cc @chrishoffman @manuel-sousa @romanek-adam
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
I'll create a PR soon.
cc @chrishoffman @manuel-sousa @romanek-adam
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/messaging/rabbitmq_plugin.py b/lib/ansible/modules/messaging/rabbitmq_plugin.py
--- a/lib/ansible/modules/messaging/rabbitmq_plugin.py
+++ b/lib/ansible/modules/messaging/rabbitmq_plugin.py
@@ -16,46 +16,55 @@
 DOCUMENTATION = '''
 ---
 module: rabbitmq_plugin
-short_description: Adds or removes plugins to RabbitMQ
+short_description: Manage RabbitMQ plugins
 description:
-  - Enables or disables RabbitMQ plugins
+  - Manage RabbitMQ plugins.
 version_added: "1.1"
-author: '"Chris Hoffman (@chrishoffman)"'
+author:
+  - Chris Hoffman (@chrishoffman)
 options:
   names:
     description:
-      - Comma-separated list of plugin names
+      - Comma-separated list of plugin names.
     required: true
-    default: null
     aliases: [name]
   new_only:
     description:
-      - Only enable missing plugins
-      - Does not disable plugins that are not in the names list
-    required: false
+      - Only enable missing plugins.
+      - Does not disable plugins that are not in the names list.
+    type: bool
     default: "no"
-    choices: [ "yes", "no" ]
   state:
     description:
-      - Specify if plugins are to be enabled or disabled
-    required: false
+      - Specify if plugins are to be enabled or disabled.
     default: enabled
     choices: [enabled, disabled]
   prefix:
     description:
-      - Specify a custom install prefix to a Rabbit
-    required: false
+      - Specify a custom install prefix to a Rabbit.
     version_added: "1.3"
-    default: null
 '''
 
 EXAMPLES = '''
-# Enables the rabbitmq_management plugin
-- rabbitmq_plugin:
+- name: Enables the rabbitmq_management plugin
+  rabbitmq_plugin:
     names: rabbitmq_management
     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
 
 from ansible.module_utils.basic import AnsibleModule
diff --git a/lib/ansible/modules/windows/win_rabbitmq_plugin.py b/lib/ansible/modules/windows/win_rabbitmq_plugin.py
new file mode 100644
--- /dev/null
+++ b/lib/ansible/modules/windows/win_rabbitmq_plugin.py
@@ -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"]
+'''


Test patch: