# Unlock and Lock users across multiple machines

**URL:** <https://forum.ansible.com/t/unlock-and-lock-users-across-multiple-machines/21637>\
**Category:** Ansible Project\
**Created:** [June 1, 2016, 6:01pm UTC](https://forum.ansible.com/t/unlock-and-lock-users-across-multiple-machines/21637 "2016-06-01T18:01:41Z")\
**Posts on this page:** 6\
**Page:** 1

<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, 6:01pm UTC](https://forum.ansible.com/t/unlock-and-lock-users-across-multiple-machines/21637/1 "2016-06-01T18:01:41Z")

</div>

Right now my system consists of 20 machines. When we make user accounts it locks them by default on creation with a default password they must change upon initial login.

Instead of locking the same account on each system individually I would like to be able to use ansible to either execute this ad-hoc or via a playbook.

Anyone else have this type of issue and how did you solve it.

1. If I run: sudo passwd -u _someusername_ It will prompt me for my sudo credentials and then unlock the user. No problem. Now do it 19 more times, got to be a better way.

2. If i run it adhoc using ansible like so I get a response saying only root can do this.

ansible -m shell -a “passwd -u username” “test-server-suite” --ask-become-pass

Is there no way to run that ad hoc from command line or as a playbook using the user module or another module to unlock the same user across my entire architecture?

Again any help is appreciated.

---

<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, 6:17pm UTC](https://forum.ansible.com/t/unlock-and-lock-users-across-multiple-machines/21637/2 "2016-06-01T18:17:31Z")

</div>

I figured it out, not sure if anyone else does it this way ad hoc but its a start

ansible test-server-suite -s -m shell -a “passwd -u username” -K

Prompts for my sudo credentials and away it goes. Worked across all 20 machines. Might be messy or can be simplified but I am learning as I go. Hope it helps someone else.

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [June 1, 2016, 6:18pm UTC](https://forum.ansible.com/t/unlock-and-lock-users-across-multiple-machines/21637/3 "2016-06-01T18:18:04Z")

</div>

You are missing the -b switch to actually run this command via the  
default become method (aka sudo). You only tell it to prompt you for  
the sudo password, but do not tell it to actually use sudo...

Johannes

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [June 1, 2016, 6:20pm UTC](https://forum.ansible.com/t/unlock-and-lock-users-across-multiple-machines/21637/4 "2016-06-01T18:20:16Z")

</div>

You can put this into a playbook, too.

- hosts: foobar  
&nbsp;&nbsp;become: true  
&nbsp;&nbsp;become\_method: sudo

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;- name: "Do something"  
&nbsp;&nbsp;&nbsp;&nbsp;command: passwd -u username

Untested.

Also, why not use the user module to set the password?

Johannes

---

<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, 6:24pm UTC](https://forum.ansible.com/t/unlock-and-lock-users-across-multiple-machines/21637/5 "2016-06-01T18:24:06Z")

</div>

I will give that playbook a try. I didnt want to change the default password we already had provided them on initial account creation, just let them do it when they logged in. It remains locked until they tell me they are ready to login the first time.

---

<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, 6:34pm UTC](https://forum.ansible.com/t/unlock-and-lock-users-across-multiple-machines/21637/6 "2016-06-01T18:34:38Z")

</div>

For the password feature yes when creating new accounts we will make use of that, the uid/guid, and other user module features
