Repository: ansible/ansible

Issue:
rabbitmq_user throws "ValueError: need more than 1 value to unpack"
<!---
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 or feature
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path
-->

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.2.0
  config file = /Users/rushpu/Program/Devops/Ansible/ansible.cfg
  configured module search path = [u'/Users/rushpu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/rushpu/.pyenv/versions/2.7.12/envs/ansible/lib/python2.7/site-packages/ansible
  executable location = /Users/rushpu/.pyenv/versions/ansible/bin/ansible
  python version = 2.7.12 (default, Jul 26 2017, 16:16:30) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
```
ANSIBLE_PIPELINING(/Users/rushpu/Program/Devops/Ansible/ansible.cfg) = True
ANSIBLE_SSH_CONTROL_PATH(/Users/rushpu/Program/Devops/Ansible/ansible.cfg) = /tmp/ansible-ssh-%%h-%%p-%%r
ANSIBLE_SSH_RETRIES(/Users/rushpu/Program/Devops/Ansible/ansible.cfg) = 2
DEFAULT_CALLBACK_PLUGIN_PATH(/Users/rushpu/Program/Devops/Ansible/ansible.cfg) = [u'/Users/rushpu/Program/Devops/Ansible/plugins/human_log.py']
DEFAULT_LOG_PATH(/Users/rushpu/Program/Devops/Ansible/ansible.cfg) = /Users/rushpu/Program/Devops/Ansible/log
DEFAULT_PRIVATE_KEY_FILE(/Users/rushpu/Program/Devops/Ansible/ansible.cfg) = /Users/rushpu/.ssh/id_rsa
DEFAULT_ROLES_PATH(/Users/rushpu/Program/Devops/Ansible/ansible.cfg) = [u'/Users/rushpu/Program/Devops/Ansible/roles']
DEFAULT_TIMEOUT(/Users/rushpu/Program/Devops/Ansible/ansible.cfg) = 20
HOST_KEY_CHECKING(/Users/rushpu/Program/Devops/Ansible/ansible.cfg) = False
RETRY_FILES_ENABLED(/Users/rushpu/Program/Devops/Ansible/ansible.cfg) = False
```

##### 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.
-->
```
System Version: macOS 10.12.6 (16G1114)
Kernel Version: Darwin 16.7.0
```

##### SUMMARY
<!--- Explain the problem briefly -->

##### 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: add rabbitmq user
  rabbitmq_user:
    user: "user"
    password: "password"
    vhost: /
    tags: monitoring
    configure_priv: .*
    read_priv: .*
    write_priv: .*
    state: present
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
```
add a rabbitmq user
```

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
TASK [beoprabbitmq : add rabbitmq user] *******************************************************************************************************
task path: /Users/rushpu/Program/Devops/Ansible/roles/beoprabbitmq/tasks/main.yml:25
Using module file /Users/rushpu/.pyenv/versions/2.7.12/envs/ansible/lib/python2.7/site-packages/ansible/modules/messaging/rabbitmq_user.py
<hostip> ESTABLISH SSH CONNECTION FOR USER: root
<hostip> SSH: EXEC sshpass -d59 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=22 -o 'IdentityFile="/Users/rushpu/.ssh/id_rsa"' -o User=root -o ConnectTimeout=20 -o ControlPath=/tmp/ansible-ssh-%h-%p-%r hostip '/bin/sh -c '"'"'/usr/bin/python && sleep 0'"'"''
<hostip> (1, '', 'Traceback (most recent call last):\n  File "/tmp/ansible_PxsyvA/ansible_module_rabbitmq_user.py", line 307, in <module>\n    main()\n  File "/tmp/ansible_PxsyvA/ansible_module_rabbitmq_user.py", line 280, in main\n    if rabbitmq_user.get():\n  File "/tmp/ansible_PxsyvA/ansible_module_rabbitmq_user.py", line 176, in get\n    self._permissions = self._get_permissions()\n  File "/tmp/ansible_PxsyvA/ansible_module_rabbitmq_user.py", line 185, in _get_permissions\n    vhost, configure_priv, write_priv, read_priv = perm.split(\'\\t\')\nValueError: need more than 1 value to unpack\n')
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_PxsyvA/ansible_module_rabbitmq_user.py", line 307, in <module>
    main()
  File "/tmp/ansible_PxsyvA/ansible_module_rabbitmq_user.py", line 280, in main
    if rabbitmq_user.get():
  File "/tmp/ansible_PxsyvA/ansible_module_rabbitmq_user.py", line 176, in get
    self._permissions = self._get_permissions()
  File "/tmp/ansible_PxsyvA/ansible_module_rabbitmq_user.py", line 185, in _get_permissions
    vhost, configure_priv, write_priv, read_priv = perm.split('\t')
ValueError: need more than 1 value to unpack

fatal: [rabbitmq]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_PxsyvA/ansible_module_rabbitmq_user.py\", line 307, in <module>\n    main()\n  File \"/tmp/ansible_PxsyvA/ansible_module_rabbitmq_user.py\", line 280, in main\n    if rabbitmq_user.get():\n  File \"/tmp/ansible_PxsyvA/ansible_module_rabbitmq_user.py\", line 176, in get\n    self._permissions = self._get_permissions()\n  File \"/tmp/ansible_PxsyvA/ansible_module_rabbitmq_user.py\", line 185, in _get_permissions\n    vhost, configure_priv, write_priv, read_priv = perm.split('\\t')\nValueError: need more than 1 value to unpack\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 1
}
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/messaging/rabbitmq_user.py b/lib/ansible/modules/messaging/rabbitmq_user.py
--- a/lib/ansible/modules/messaging/rabbitmq_user.py
+++ b/lib/ansible/modules/messaging/rabbitmq_user.py
@@ -178,7 +178,7 @@ def get(self):
         return False
 
     def _get_permissions(self):
-        perms_out = self._exec(['list_user_permissions', self.username], True)
+        perms_out = [perm for perm in self._exec(['list_user_permissions', self.username], True) if perm.strip()]
 
         perms_list = list()
         for perm in perms_out:


Test patch: