ansible/ansible — pull request #7028 by jjshoe (2014-04-16 20:13:58+00:00)
Title: Fix idempotency related to modifying groups

Test:
````
- name: Add bob
sudo: yes
user: name=bob

- name: Add tom
sudo: yes
user: name=tom

- name: Add some groups
sudo: yes
group: name={{ item }}
with_items:
- bob
- car
- tom
- shovel

# All bob
- name: Capture what groups bob has
shell: cat /etc/group | grep bob
register: bob_output

- name: See what groups bob has
debug: var=bob_output

- name: Add bob to groups bob and car
sudo: yes
user: name=bob groups=bob,car

- name: Capture what groups bob has
shell: cat /etc/group | grep bob
register: bob_output

- name: See what groups bob has
debug: var=bob_output

# All tom
- name: Capture what groups tom has
shell: cat /etc/group | grep tom
register: tom_output

- name: See what groups tom has
debug: var=tom_output

- name: Add tom to groups tom and shovel
sudo: yes
user: name=tom groups=tom,shovel append=1

- name: Capture what groups tom has
shell: cat /etc/group | grep tom
register: tom_output

- name: See what groups tom has
debug: var=tom_output
````

Before:
````
jjshoe@joel-desktop:~/test-vagrant$ vagrant up
Bringing machine 'box1' up with 'virtualbox' provider...
==> box1: Importing base box 'saucy-server'...
==> box1: Matching MAC address for NAT networking...
==> box1: Setting the name of the VM: test-vagrant_box1_1397678910913_26903
==> box1: Clearing any previously set forwarded ports...
==> box1: Clearing any previously set network interfaces...
==> box1: Preparing network interfaces based on configuration...
box1: Adapter 1: nat
box1: Adapter 2: hostonly
==> box1: Forwarding ports...
box1: 22 => 2222 (adapter 1)
==> box1: Booting VM...
==> box1: Waiting for machine to boot. This may take a few minutes...
box1: SSH address: 127.0.0.1:2222
box1: SSH username: vagrant
box1: SSH auth method: private key
box1: Error: Connection timeout. Retrying...
==> box1: Machine booted and ready!
==> box1: Checking for guest additions in VM...
box1: The guest additions on this VM do not match the installed version of
box1: VirtualBox! In most cases this is fine, but in rare cases it can
box1: prevent things such as shared folders from working properly. If you see
box1: shared folder errors, please make sure the guest additions within the
box1: virtual machine match the version of VirtualBox you have installed on
box1: your host and reload your VM.
box1:
box1: Guest Additions Version: 4.2.16
box1: VirtualBox Version: 4.1
==> box1: Configuring and enabling network interfaces...
==> box1: Mounting shared folders...
box1: /vagrant => /home/jjshoe/test-vagrant
==> box1: Running provisioner: ansible...

PLAY [joel] *******************************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.33.10]

TASK: [vault | Add bob] *******************************************************
changed: [192.168.33.10]

TASK: [vault | Add tom] *******************************************************
changed: [192.168.33.10]

TASK: [vault | Add some groups] ***********************************************
ok: [192.168.33.10] => (item=bob)
changed: [192.168.33.10] => (item=car)
ok: [192.168.33.10] => (item=tom)
changed: [192.168.33.10] => (item=shovel)

TASK: [vault | Capture what groups bob has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups bob has] ***************************************
ok: [192.168.33.10] => {
"bob_output": {
"changed": true,
"cmd": "cat /etc/group | grep bob ",
"delta": "0:00:00.002072",
"end": "2014-04-16 20:09:07.577656",
"invocation": {
"module_args": "cat /etc/group | grep bob",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:09:07.575584",
"stderr": "",
"stdout": "bob:x:1002:",
"stdout_lines": [
"bob:x:1002:"
]
},
"item": ""
}

TASK: [vault | Add bob to groups bob and car] *********************************
changed: [192.168.33.10]

TASK: [vault | Capture what groups bob has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups bob has] ***************************************
ok: [192.168.33.10] => {
"bob_output": {
"changed": true,
"cmd": "cat /etc/group | grep bob ",
"delta": "0:00:00.002138",
"end": "2014-04-16 20:09:07.738881",
"invocation": {
"module_args": "cat /etc/group | grep bob",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:09:07.736743",
"stderr": "",
"stdout": "bob:x:1002:bob\ncar:x:1004:bob",
"stdout_lines": [
"bob:x:1002:bob",
"car:x:1004:bob"
]
},
"item": ""
}

TASK: [vault | Capture what groups tom has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups tom has] ***************************************
ok: [192.168.33.10] => {
"item": "",
"tom_output": {
"changed": true,
"cmd": "cat /etc/group | grep tom ",
"delta": "0:00:00.002105",
"end": "2014-04-16 20:09:07.812642",
"invocation": {
"module_args": "cat /etc/group | grep tom",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:09:07.810537",
"stderr": "",
"stdout": "tom:x:1003:",
"stdout_lines": [
"tom:x:1003:"
]
}
}

TASK: [vault | Add tom to groups tom and shovel] ******************************
changed: [192.168.33.10]

TASK: [vault | Capture what groups tom has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups tom has] ***************************************
ok: [192.168.33.10] => {
"item": "",
"tom_output": {
"changed": true,
"cmd": "cat /etc/group | grep tom ",
"delta": "0:00:00.001936",
"end": "2014-04-16 20:09:07.972767",
"invocation": {
"module_args": "cat /etc/group | grep tom",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:09:07.970831",
"stderr": "",
"stdout": "tom:x:1003:tom\nshovel:x:1005:tom",
"stdout_lines": [
"tom:x:1003:tom",
"shovel:x:1005:tom"
]
}
}

PLAY RECAP ********************************************************************
192.168.33.10 : ok=14 changed=9 unreachable=0 failed=0

jjshoe@joel-desktop:~/test-vagrant$ vagrant provision
==> box1: Running provisioner: ansible...

PLAY [joel] *******************************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.33.10]

TASK: [vault | Add bob] *******************************************************
ok: [192.168.33.10]

TASK: [vault | Add tom] *******************************************************
ok: [192.168.33.10]

TASK: [vault | Add some groups] ***********************************************
ok: [192.168.33.10] => (item=bob)
ok: [192.168.33.10] => (item=car)
ok: [192.168.33.10] => (item=tom)
ok: [192.168.33.10] => (item=shovel)

TASK: [vault | Capture what groups bob has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups bob has] ***************************************
ok: [192.168.33.10] => {
"bob_output": {
"changed": true,
"cmd": "cat /etc/group | grep bob ",
"delta": "0:00:00.002007",
"end": "2014-04-16 20:09:41.088894",
"invocation": {
"module_args": "cat /etc/group | grep bob",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:09:41.086887",
"stderr": "",
"stdout": "bob:x:1002:bob\ncar:x:1004:bob",
"stdout_lines": [
"bob:x:1002:bob",
"car:x:1004:bob"
]
},
"item": ""
}

TASK: [vault | Add bob to groups bob and car] *********************************
changed: [192.168.33.10]

TASK: [vault | Capture what groups bob has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups bob has] ***************************************
ok: [192.168.33.10] => {
"bob_output": {
"changed": true,
"cmd": "cat /etc/group | grep bob ",
"delta": "0:00:00.002852",
"end": "2014-04-16 20:09:41.261022",
"invocation": {
"module_args": "cat /etc/group | grep bob",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:09:41.258170",
"stderr": "",
"stdout": "bob:x:1002:bob\ncar:x:1004:bob",
"stdout_lines": [
"bob:x:1002:bob",
"car:x:1004:bob"
]
},
"item": ""
}

TASK: [vault | Capture what groups tom has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups tom has] ***************************************
ok: [192.168.33.10] => {
"item": "",
"tom_output": {
"changed": true,
"cmd": "cat /etc/group | grep tom ",
"delta": "0:00:00.002160",
"end": "2014-04-16 20:09:41.331299",
"invocation": {
"module_args": "cat /etc/group | grep tom",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:09:41.329139",
"stderr": "",
"stdout": "tom:x:1003:tom\nshovel:x:1005:tom",
"stdout_lines": [
"tom:x:1003:tom",
"shovel:x:1005:tom"
]
}
}

TASK: [vault | Add tom to groups tom and shovel] ******************************
changed: [192.168.33.10]

TASK: [vault | Capture what groups tom has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups tom has] ***************************************
ok: [192.168.33.10] => {
"item": "",
"tom_output": {
"changed": true,
"cmd": "cat /etc/group | grep tom ",
"delta": "0:00:00.005413",
"end": "2014-04-16 20:09:41.497306",
"invocation": {
"module_args": "cat /etc/group | grep tom",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:09:41.491893",
"stderr": "",
"stdout": "tom:x:1003:tom\nshovel:x:1005:tom",
"stdout_lines": [
"tom:x:1003:tom",
"shovel:x:1005:tom"
]
}
}

PLAY RECAP ********************************************************************
192.168.33.10 : ok=14 changed=6 unreachable=0 failed=0

jjshoe@joel-desktop:~/test-vagrant$
````

After:
````
jjshoe@joel-desktop:~/test-vagrant$ vagrant provision
==> box1: Running provisioner: ansible...

PLAY [joel] *******************************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.33.10]

TASK: [vault | Add bob] *******************************************************
changed: [192.168.33.10]

TASK: [vault | Add tom] *******************************************************
changed: [192.168.33.10]

TASK: [vault | Add some groups] ***********************************************
ok: [192.168.33.10] => (item=bob)
changed: [192.168.33.10] => (item=car)
ok: [192.168.33.10] => (item=tom)
changed: [192.168.33.10] => (item=shovel)

TASK: [vault | Capture what groups bob has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups bob has] ***************************************
ok: [192.168.33.10] => {
"bob_output": {
"changed": true,
"cmd": "cat /etc/group | grep bob ",
"delta": "0:00:00.001946",
"end": "2014-04-16 20:13:03.671162",
"invocation": {
"module_args": "cat /etc/group | grep bob",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:13:03.669216",
"stderr": "",
"stdout": "bob:x:1002:",
"stdout_lines": [
"bob:x:1002:"
]
},
"item": ""
}

TASK: [vault | Add bob to groups bob and car] *********************************
changed: [192.168.33.10]

TASK: [vault | Capture what groups bob has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups bob has] ***************************************
ok: [192.168.33.10] => {
"bob_output": {
"changed": true,
"cmd": "cat /etc/group | grep bob ",
"delta": "0:00:00.002667",
"end": "2014-04-16 20:13:03.832972",
"invocation": {
"module_args": "cat /etc/group | grep bob",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:13:03.830305",
"stderr": "",
"stdout": "bob:x:1002:bob\ncar:x:1004:bob",
"stdout_lines": [
"bob:x:1002:bob",
"car:x:1004:bob"
]
},
"item": ""
}

TASK: [vault | Capture what groups tom has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups tom has] ***************************************
ok: [192.168.33.10] => {
"item": "",
"tom_output": {
"changed": true,
"cmd": "cat /etc/group | grep tom ",
"delta": "0:00:00.002125",
"end": "2014-04-16 20:13:03.913651",
"invocation": {
"module_args": "cat /etc/group | grep tom",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:13:03.911526",
"stderr": "",
"stdout": "tom:x:1003:",
"stdout_lines": [
"tom:x:1003:"
]
}
}

TASK: [vault | Add tom to groups tom and shovel] ******************************
changed: [192.168.33.10]

TASK: [vault | Capture what groups tom has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups tom has] ***************************************
ok: [192.168.33.10] => {
"item": "",
"tom_output": {
"changed": true,
"cmd": "cat /etc/group | grep tom ",
"delta": "0:00:00.001676",
"end": "2014-04-16 20:13:04.071668",
"invocation": {
"module_args": "cat /etc/group | grep tom",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:13:04.069992",
"stderr": "",
"stdout": "tom:x:1003:tom\nshovel:x:1005:tom",
"stdout_lines": [
"tom:x:1003:tom",
"shovel:x:1005:tom"
]
}
}

PLAY RECAP ********************************************************************
192.168.33.10 : ok=14 changed=9 unreachable=0 failed=0

jjshoe@joel-desktop:~/test-vagrant$ vagrant provision
==> box1: Running provisioner: ansible...

PLAY [joel] *******************************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.33.10]

TASK: [vault | Add bob] *******************************************************
ok: [192.168.33.10]

TASK: [vault | Add tom] *******************************************************
ok: [192.168.33.10]

TASK: [vault | Add some groups] ***********************************************
ok: [192.168.33.10] => (item=bob)
ok: [192.168.33.10] => (item=car)
ok: [192.168.33.10] => (item=tom)
ok: [192.168.33.10] => (item=shovel)

TASK: [vault | Capture what groups bob has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups bob has] ***************************************
ok: [192.168.33.10] => {
"bob_output": {
"changed": true,
"cmd": "cat /etc/group | grep bob ",
"delta": "0:00:00.002098",
"end": "2014-04-16 20:13:07.618935",
"invocation": {
"module_args": "cat /etc/group | grep bob",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:13:07.616837",
"stderr": "",
"stdout": "bob:x:1002:bob\ncar:x:1004:bob",
"stdout_lines": [
"bob:x:1002:bob",
"car:x:1004:bob"
]
},
"item": ""
}

TASK: [vault | Add bob to groups bob and car] *********************************
ok: [192.168.33.10]

TASK: [vault | Capture what groups bob has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups bob has] ***************************************
ok: [192.168.33.10] => {
"bob_output": {
"changed": true,
"cmd": "cat /etc/group | grep bob ",
"delta": "0:00:00.002170",
"end": "2014-04-16 20:13:07.766252",
"invocation": {
"module_args": "cat /etc/group | grep bob",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:13:07.764082",
"stderr": "",
"stdout": "bob:x:1002:bob\ncar:x:1004:bob",
"stdout_lines": [
"bob:x:1002:bob",
"car:x:1004:bob"
]
},
"item": ""
}

TASK: [vault | Capture what groups tom has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups tom has] ***************************************
ok: [192.168.33.10] => {
"item": "",
"tom_output": {
"changed": true,
"cmd": "cat /etc/group | grep tom ",
"delta": "0:00:00.001970",
"end": "2014-04-16 20:13:07.829838",
"invocation": {
"module_args": "cat /etc/group | grep tom",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:13:07.827868",
"stderr": "",
"stdout": "tom:x:1003:tom\nshovel:x:1005:tom",
"stdout_lines": [
"tom:x:1003:tom",
"shovel:x:1005:tom"
]
}
}

TASK: [vault | Add tom to groups tom and shovel] ******************************
ok: [192.168.33.10]

TASK: [vault | Capture what groups tom has] ***********************************
changed: [192.168.33.10]

TASK: [vault | See what groups tom has] ***************************************
ok: [192.168.33.10] => {
"item": "",
"tom_output": {
"changed": true,
"cmd": "cat /etc/group | grep tom ",
"delta": "0:00:00.003144",
"end": "2014-04-16 20:13:07.983156",
"invocation": {
"module_args": "cat /etc/group | grep tom",
"module_name": "shell"
},
"item": "",
"rc": 0,
"start": "2014-04-16 20:13:07.980012",
"stderr": "",
"stdout": "tom:x:1003:tom\nshovel:x:1005:tom",
"stdout_lines": [
"tom:x:1003:tom",
"shovel:x:1005:tom"
]
}
}

PLAY RECAP ********************************************************************
192.168.33.10 : ok=14 changed=4 unreachable=0 failed=0

jjshoe@joel-desktop:~/test-vagrant$

````