# How to use changed\_when with user:

**URL:** <https://forum.ansible.com/t/how-to-use-changed-when-with-user/15594>\
**Category:** Ansible Project\
**Created:** [July 2, 2014, 6:44pm UTC](https://forum.ansible.com/t/how-to-use-changed-when-with-user/15594 "2014-07-02T18:44:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenton\_Brede](https://avatars.discourse-cdn.com/v4/letter/k/db5fbb/32.png) [@Kenton\_Brede](https://forum.ansible.com/u/Kenton_Brede)\
**Post date:** [July 2, 2014, 6:44pm UTC](https://forum.ansible.com/t/how-to-use-changed-when-with-user/15594/1 "2014-07-02T18:44:56Z")

</div>

Trying to learn more about how to use Ansible. I’ve got a situation where a mix of local and LDAP users may exist on a box. In some situations user1 may either be a local user or LDAP user.

I created a task to remove certain users. The LDAP users are always marked as “changed” when obviously they aren’t. Is there a way to modify the report to say “ok?”

I know how to do this with “command:” but not “user:.”

I get “error while evaluating conditional” when using, changed\_when: “result.state != absent”

Running debug on “result” shows LDAP users have state=absent:

“item”: “user1”,  
“name”: “user1”,  
“remove”: false,  
“shell”: “/bin/bash”,  
“state”: “absent”,  
“stderr”: “userdel: error deleting password entry\nuserdel: error deleting shadow password entry\n”,

What I’d like to do is something like: not\_changed\_when: “result.state == absent”

Is there anyway to translate that into something that would work?

Thanks,  
Kent

tasks:

- name: remove users  
user: name={{ item }} state=absent  
register: result  
not\_changed\_when: “result.state != absent”  
with\_items:
- local-user1
- ldap-user1
- ldap-user2

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 2, 2014, 10:18pm UTC](https://forum.ansible.com/t/how-to-use-changed-when-with-user/15594/2 "2014-07-02T22:18:36Z")

</div>

There is nothing called “not\_changed\_when” so you are making syntax up that won’t work 🙂

It seems you want to say

changed\_when: “result.state == ‘absent’”

However this also seems excessive, because the default state of the module should be to return unchanged if it didn’t make any changes.

Ergo, changed\_when can be omitted.

If you are having an error when deleting a pre-deleted user, this won’t help anyway, and I’d like more info. Please include the output of running this step with “-v”, unfiltered, rather than just showing the middle of it, and let me know your OS and ansible version.

Thanks!
