Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

user

ANSIBLE VERSION

ansible 2.4.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/v683653/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, May 3 2017, 07:55:04) [GCC 4.8.5 20150623 (Red Hat 4.8.5-14)]

CONFIGURATION

PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 30

RETRY_FILES_SAVE_PATH(/etc/ansible/ansible.cfg) = /tmp/ansibleretry

OS / ENVIRONMENT

used on rhel6 and rhel7 servers

SUMMARY

When I run the user module to remove a user, if that user doesn't exist on the system then the module reports a failure as seen below.

STEPS TO REPRODUCE

use the user module to remove a user from a system that the user doesn't exist on.

- name: Remove user account
user:
state: absent
remove: yes
name: bob

EXPECTED RESULTS

If the user doesn't exist then I figured that the idempotent part would see that the user doesn't exist and would therefore report an OK but not fail.

ACTUAL RESULTS

The task fails with the error below.

fatal: [soctxqatw01]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"append": false,
"comment": null,
"createhome": true,
"expires": null,
"force": false,
"generate_ssh_key": null,
"group": null,
"groups": null,
"home": null,
"local": null,
"login_class": null,
"move_home": false,
"name": "zockmi",
"non_unique": false,
"password": null,
"remove": true,
"seuser": null,
"shell": null,
"skeleton": null,
"ssh_key_bits": 0,
"ssh_key_comment": "ansible-generated on soctxqatw01.gsoc.verizon.com",
"ssh_key_file": null,
"ssh_key_passphrase": null,
"ssh_key_type": "rsa",
"state": "absent",
"system": false,
"uid": null,
"update_password": "always"
}
},
"msg": "userdel: cannot remove entry 'zockmi' from /etc/passwd\n",
"name": "zockmi",
"rc": 1
}

Issue 2:
From @avacam on 2014-12-10T18:58:20Z

Issue Type:

Bug Report

Component Name:

user module

Ansible Version:

1.5.4

Environment:

Ubuntu 14.04

Summary:

Command to remove an account fails when there is a non-local copy of the account visible to the authentication system.

Steps To Reproduce:

prerequisites:

a. server configured with single-sign-on service (AD, LDAP, etc)

b. user 'foobar' exists in SSO system.

Create local 'foobar' user.

run user module to remove local account. Example:

- name: remove users
user: name={{ item }} state=absent remove=yes
with_items:
- foobar

run user module again with local account already removed.

Expected Results:

no action

Actual Results:

Resulting error:

failed: [servername] => (item=foobar) => {"failed": true, "item": "foobar", "name": "foobar", "rc": 1}

msg: userdel: cannot remove entry 'foobar' from /etc/passwd

Issuing the command to remove an account fails when there is a non-local copy of that account visible to the authentication system.

When a server is configured with local and non-local account systems, like when using LDAP, user.py will report an error if the command is issued to remove an account that does not exist locally on the server. I ran into this issue when I was removing local copies of user accounts that also exist in the LDAP/AD environment. Note: The intention is not to remove them from the directory system, just the local account.

Copied from original issue: ansible/ansible-modules-core#491