<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">user</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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)]
"><pre class="notranslate"><code class="notranslate">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)]

</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 30<br>
RETRY_FILES_SAVE_PATH(/etc/ansible/ansible.cfg) = /tmp/ansibleretry</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">used on rhel6 and rhel7 servers</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">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.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">use the user module to remove a user from a system that the user doesn't exist on.</p>

<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  - name: Remove user account
    user:
      state: absent
      remove: yes
      name: bob
"><pre class="notranslate">  - <span class="pl-ent">name</span>: <span class="pl-s">Remove user account</span>
    <span class="pl-ent">user</span>:
      <span class="pl-ent">state</span>: <span class="pl-s">absent</span>
      <span class="pl-ent">remove</span>: <span class="pl-s">yes</span>
      <span class="pl-ent">name</span>: <span class="pl-s">bob</span>
</pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">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.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">The task fails with the error below.</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [soctxqatw01]: FAILED! =&gt; {
    &quot;changed&quot;: false,
    &quot;failed&quot;: true,
    &quot;invocation&quot;: {
        &quot;module_args&quot;: {
            &quot;append&quot;: false,
            &quot;comment&quot;: null,
            &quot;createhome&quot;: true,
            &quot;expires&quot;: null,
            &quot;force&quot;: false,
            &quot;generate_ssh_key&quot;: null,
            &quot;group&quot;: null,
            &quot;groups&quot;: null,
            &quot;home&quot;: null,
            &quot;local&quot;: null,
            &quot;login_class&quot;: null,
            &quot;move_home&quot;: false,
            &quot;name&quot;: &quot;zockmi&quot;,
            &quot;non_unique&quot;: false,
            &quot;password&quot;: null,
            &quot;remove&quot;: true,
            &quot;seuser&quot;: null,
            &quot;shell&quot;: null,
            &quot;skeleton&quot;: null,
            &quot;ssh_key_bits&quot;: 0,
            &quot;ssh_key_comment&quot;: &quot;ansible-generated on soctxqatw01.gsoc.verizon.com&quot;,
            &quot;ssh_key_file&quot;: null,
            &quot;ssh_key_passphrase&quot;: null,
            &quot;ssh_key_type&quot;: &quot;rsa&quot;,
            &quot;state&quot;: &quot;absent&quot;,
            &quot;system&quot;: false,
            &quot;uid&quot;: null,
            &quot;update_password&quot;: &quot;always&quot;
        }
    },
    &quot;msg&quot;: &quot;userdel: cannot remove entry 'zockmi' from /etc/passwd\n&quot;,
    &quot;name&quot;: &quot;zockmi&quot;,
    &quot;rc&quot;: 1
}
"><pre class="notranslate"><code class="notranslate">fatal: [soctxqatw01]: FAILED! =&gt; {
    "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
}

</code></pre></div>
<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/avacam/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/avacam">@avacam</a> on 2014-12-10T18:58:20Z</p>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Component Name:</h5>
<p dir="auto">user module</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">1.5.4</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Ubuntu 14.04</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Command to remove an account fails when there is a non-local copy of the account visible to the authentication system.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">prerequisites:<br>
a. server configured with single-sign-on service (AD, LDAP, etc)<br>
b. user 'foobar' exists in SSO system.</p>
<ol dir="auto">
<li>Create local 'foobar' user.</li>
<li>run user module to remove local account.  Example:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  - name: remove users
    user: name={{ item }} state=absent remove=yes
    with_items:
      - foobar"><pre class="notranslate"><code class="notranslate">  - name: remove users
    user: name={{ item }} state=absent remove=yes
    with_items:
      - foobar
</code></pre></div>
<ol dir="auto">
<li>run user module again with local account already removed.</li>
</ol>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">no action</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">Resulting error:<br>
failed: [servername] =&gt; (item=foobar) =&gt; {"failed": true, "item": "foobar", "name": "foobar", "rc": 1}<br>
msg: userdel: cannot remove entry 'foobar' from /etc/passwd</p>
<hr>
<p dir="auto">Issuing the command to remove an account fails when there is a non-local copy of that account visible to the authentication system.</p>
<p dir="auto">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.</p>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="51596643" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/491" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/491/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/491">ansible/ansible-modules-core#491</a></p>