Repository: ansible/ansible-modules-extras

Issue:
rabbitmq_user module inserts "node" parameter even when it was not given
rabbitmq_user tries to run 

```
/usr/sbin/rabbitmqctl -q -n rabbit list_users
```

even, when there was no node parameter defined.

The correct behavior would be:

```
/usr/sbin/rabbitmqctl -q list_users
```

The difference is that the later works on rabbit@local but the previos does not. So if there's a parameter, and it does not have a value, the correct method would be not to give that parameter to the underlying process with a default but let it handle the missing (optional!) parameter the way it was intended.

effect:

failed: [local] => (item=rabbitmq_user_remove) => {"cmd": "/usr/sbin/rabbitmqctl -q -n rabbit list_users", "failed": true, "item": "rabbitmq_user_remove", "rc": 2}
stderr: Error: unable to connect to node rabbit@local: nodedown
# DIAGNOSTICS

attempted to contact: [rabbit@local]

rabbit@local:
- connected to epmd (port 4369) on local
- epmd reports node 'rabbit' running on port 25672
- TCP connection succeeded but Erlang distribution failed
- suggestion: hostname mismatch?
- suggestion: is the cookie set correctly?
- suggestion: is the Erlang distribution using TLS?

rabbitmq_user runs the following command, when I'm trying to remove the guest:

but the simpler command works fine:

```
$ sudo /usr/sbin/rabbitmqctl -q list_users
guest   [administrator]
```

Of course I could work around this with setting the node parameter, but that depends on the hostname, in this case:

```
$ sudo /usr/sbin/rabbitmqctl -q -n rabbit@develbox list_users
guest   [administrator]
```

So if you don't have information, don't give a bad default to a not necessary (optional) parameter, or if its very-very neccessary this case you should use rabbit@hostname with the current hosts name.

rabbitmq_user module inserts "node" parameter even when it was not given
rabbitmq_user tries to run 

```
/usr/sbin/rabbitmqctl -q -n rabbit list_users
```

even, when there was no node parameter defined.

The correct behavior would be:

```
/usr/sbin/rabbitmqctl -q list_users
```

The difference is that the later works on rabbit@local but the previos does not. So if there's a parameter, and it does not have a value, the correct method would be not to give that parameter to the underlying process with a default but let it handle the missing (optional!) parameter the way it was intended.

effect:

failed: [local] => (item=rabbitmq_user_remove) => {"cmd": "/usr/sbin/rabbitmqctl -q -n rabbit list_users", "failed": true, "item": "rabbitmq_user_remove", "rc": 2}
stderr: Error: unable to connect to node rabbit@local: nodedown
# DIAGNOSTICS

attempted to contact: [rabbit@local]

rabbit@local:
- connected to epmd (port 4369) on local
- epmd reports node 'rabbit' running on port 25672
- TCP connection succeeded but Erlang distribution failed
- suggestion: hostname mismatch?
- suggestion: is the cookie set correctly?
- suggestion: is the Erlang distribution using TLS?

rabbitmq_user runs the following command, when I'm trying to remove the guest:

but the simpler command works fine:

```
$ sudo /usr/sbin/rabbitmqctl -q list_users
guest   [administrator]
```

Of course I could work around this with setting the node parameter, but that depends on the hostname, in this case:

```
$ sudo /usr/sbin/rabbitmqctl -q -n rabbit@develbox list_users
guest   [administrator]
```

So if you don't have information, don't give a bad default to a not necessary (optional) parameter, or if its very-very neccessary this case you should use rabbit@hostname with the current hosts name.



Discussion:

Resolving patch:
diff --git a/messaging/rabbitmq_user.py b/messaging/rabbitmq_user.py
--- a/messaging/rabbitmq_user.py
+++ b/messaging/rabbitmq_user.py
@@ -127,7 +127,9 @@ def __init__(self, module, username, password, tags, vhost, configure_priv, writ
 
     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', '-n', self.node]
+            cmd = [self._rabbitmqctl, '-q']
+            if self.node is not None:
+                cmd.append(['-n', self.node])
             rc, out, err = self.module.run_command(cmd + args, check_rc=True)
             return out.splitlines()
         return list()
@@ -201,7 +203,7 @@ def main():
         read_priv=dict(default='^$'),
         force=dict(default='no', type='bool'),
         state=dict(default='present', choices=['present', 'absent']),
-        node=dict(default='rabbit')
+        node=dict(default=None)
     )
     module = AnsibleModule(
         argument_spec=arg_spec,


Test patch: