# Buggy code
def _get_permissions(self):
    perms_out = self._exec(["list_user_permissions", self.username], True)

    perms_list = list()
    for perm in perms_out:
        vhost, configure_priv, write_priv, read_priv = perm.split("\t")
        if not self.bulk_permissions:
            if vhost == self.permissions[0]["vhost"]:
                perms_list.append(
                    dict(
                        vhost=vhost,
                        configure_priv=configure_priv,
                        write_priv=write_priv,
                        read_priv=read_priv,
                    )
                )
                break
        else:
            perms_list.append(
                dict(
                    vhost=vhost,
                    configure_priv=configure_priv,
                    write_priv=write_priv,
                    read_priv=read_priv,
                )
            )
    return perms_list


# Traceback (ValueError)
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 &amp;&amp; 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
}

# Fixed code
def _get_permissions(self):
    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:
        vhost, configure_priv, write_priv, read_priv = perm.split("\t")
        if not self.bulk_permissions:
            if vhost == self.permissions[0]["vhost"]:
                perms_list.append(
                    dict(
                        vhost=vhost,
                        configure_priv=configure_priv,
                        write_priv=write_priv,
                        read_priv=read_priv,
                    )
                )
                break
        else:
            perms_list.append(
                dict(
                    vhost=vhost,
                    configure_priv=configure_priv,
                    write_priv=write_priv,
                    read_priv=read_priv,
                )
            )
    return perms_list