# Locked/Unlocked states in user module

**URL:** <https://forum.ansible.com/t/locked-unlocked-states-in-user-module/12415>\
**Category:** Ansible Project\
**Created:** [February 24, 2013, 9:42am UTC](https://forum.ansible.com/t/locked-unlocked-states-in-user-module/12415 "2013-02-24T09:42:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [February 24, 2013, 9:42am UTC](https://forum.ansible.com/t/locked-unlocked-states-in-user-module/12415/1 "2013-02-24T09:42:51Z")

</div>

Would a patch that adds two new states, locked and unlocked, be accepted into the user module?

My use case is this: I have a lot of machines with lots of different users that have access to different machines. (i.e. It’s not known ahead of time all of the machines a user has access to.) A user quits/retires/gets fired and I need to lock their account across all of the machines.

I currently have a play book that checks if they exist on a given machine and then if they do locks their account. While not critical I think it would be nice to do this with the user module. Something like this:

name: lock joes account  
user: name=joe state=locked

Which would check if they exist and if they do lock the account (if not already locked). The unlock state would obviously do the opposite.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 24, 2013, 2:24pm UTC](https://forum.ansible.com/t/locked-unlocked-states-in-user-module/12415/2 "2013-02-24T14:24:27Z")

</div>

Absolutely, that sounds great.

I would believe we don't need 'unlocked', as 'present' should be  
unlocked, just 'locked'.

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [February 24, 2013, 7:13pm UTC](https://forum.ansible.com/t/locked-unlocked-states-in-user-module/12415/3 "2013-02-24T19:13:57Z")

</div>

> Absolutely, that sounds great.

Cool, I'll work on it.

> I would believe we don't need 'unlocked', as 'present' should be  
> unlocked, just 'locked'.

How would one unlock the account now that it's locked?

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [February 24, 2013, 7:30pm UTC](https://forum.ansible.com/t/locked-unlocked-states-in-user-module/12415/4 "2013-02-24T19:30:32Z")

</div>

Guess I should add to this, I've not had a real-life use case for the  
'unlock' feature like I have for 'lock' but I can imagine a possible need  
to temporarily lock a users account and then unlock it at a later date. An  
example might be, the security team could ask us to temporarily lock their  
account while they undergo an internal investigation.

I'm not super concerned if you don't want the unlock, but it seems, to me  
anyway, to make sense to have.

---

<div class="post-metadata">

**Author:** ![Erick\_Tapia](https://avatars.discourse-cdn.com/v4/letter/e/a87d85/32.png) [@Erick\_Tapia](https://forum.ansible.com/u/Erick_Tapia)\
**Post date:** [March 9, 2015, 11:18pm UTC](https://forum.ansible.com/t/locked-unlocked-states-in-user-module/12415/5 "2015-03-09T23:18:28Z")

</div>

Has this feature been implemented?

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [March 10, 2015, 2:10am UTC](https://forum.ansible.com/t/locked-unlocked-states-in-user-module/12415/6 "2015-03-10T02:10:20Z")

</div>

No, I never got around to implementing it. I don’t _think_ it’s been implemented in the modules by anyone else either. I haven’t checked recently though. I usually just run a command like “passwd -l ” or “passwd -u ” to do the deed.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 10, 2015, 1:27pm UTC](https://forum.ansible.com/t/locked-unlocked-states-in-user-module/12415/7 "2015-03-10T13:27:52Z")

</div>

user expiration was the last thing implemented IIRC, this and password  
expiration are the 2 things missing from the module.

---

<div class="post-metadata">

**Author:** ![Alan\_Harkleroad1](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@Alan\_Harkleroad1](https://forum.ansible.com/u/Alan_Harkleroad1)\
**Post date:** [June 1, 2016, 5:49pm UTC](https://forum.ansible.com/t/locked-unlocked-states-in-user-module/12415/8 "2016-06-01T17:49:44Z")

</div>

Are we able to do this yet?

As we create new users across our network, by default their accounts are locked on creation for security until they are unlocked for initial use. Is there a way to use ansible to unlock the same user account across multiple machines with one playbook or ad hoc command?

---

<div class="post-metadata">

**Author:** ![enri.sephx](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@enri.sephx](https://forum.ansible.com/u/enri.sephx)\
**Post date:** [May 30, 2018, 7:02am UTC](https://forum.ansible.com/t/locked-unlocked-states-in-user-module/12415/9 "2018-05-30T07:02:51Z")

</div>

As Micheal DeHaan answers we don’t need unlock, because present is the same.  
For locking, just type two exclamation marks in the password field, for example:

- name: add admin user  
user:  
state: present  
uid: 1001  
name: example  
comment: Example User  
password: !!

---

<div class="post-metadata">

**Author:** ![enri.sephx](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@enri.sephx](https://forum.ansible.com/u/enri.sephx)\
**Post date:** [May 30, 2018, 7:04am UTC](https://forum.ansible.com/t/locked-unlocked-states-in-user-module/12415/10 "2018-05-30T07:04:35Z")

</div>

I only tested this on CentOS 7.5
