Repository: ansible/ansible

Issue:
user module does not append groups on OpenBSD
<!---
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
 - Bug Report

##### COMPONENT NAME
`user` module

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.2.2.0
  config file = /home/nmeum/src/alpine-ansible/ansible.cfg
  configured module search path = Default w/o overrides
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

From ansible.cfg:

```
[defaults]
no_target_syslog = True
```

##### OS / ENVIRONMENT
I am running Ansible from Alpine Linux and I am managing an OpenBSD 6.1 System.
<!---
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.
-->

##### SUMMARY
<!--- Explain the problem briefly -->

The `user` module has an `append` option which should append the groups listed in the `groups` option to the user's groups instead of overwriting them. Unfortunately, this doesn't seem to work on OpenBSD 6.1. Instead of appending the given groups to the existing user's groups the user's groups are overwritten.  

##### 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 -->
```
$ ssh <host> groups
nmeum git
$ ansible <host> -m user -a "name=nmeum append=yes groups=dialer"
<host> | SUCCESS => {
    "append": true, 
    "changed": true, 
    "comment": "nmeum", 
    "group": 1242, 
    "groups": "dialer", 
    "home": "/home/nmeum", 
    "move_home": false, 
    "name": "nmeum", 
    "shell": "/bin/ksh", 
    "state": "present", 
    "uid": 1242
}
$ ssh <host> groups
nmeum dialer
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
In the last step above the output of the `groups(1)` program should have been `nmeum git dialer`.

##### ACTUAL RESULTS
Instead of appending the dialer group to the user's secondary groups, the user's secondary groups have been set to `dialer` instead.


Discussion:
I commit that this bug persist also in 2.3.0.0.

Resolving patch:
diff --git a/lib/ansible/modules/system/user.py b/lib/ansible/modules/system/user.py
--- a/lib/ansible/modules/system/user.py
+++ b/lib/ansible/modules/system/user.py
@@ -1028,7 +1028,7 @@ def modify_user(self):
         if self.groups is not None:
             current_groups = self.user_group_membership()
             groups_need_mod = False
-            groups_option = '-G'
+            groups_option = '-S'
             groups = []
 
             if self.groups == '':
@@ -1042,7 +1042,7 @@ def modify_user(self):
                     if self.append:
                         for g in groups:
                             if g in group_diff:
-                                groups_option = '-S'
+                                groups_option = '-G'
                                 groups_need_mod = True
                                 break
                     else:


Test patch: