Ansible Pilot

Enable user account - Ansible module user

How to enable a user without password lock and with the appropriate shell in Linux.

How to Enable a user account with Ansible?

I’m going to show you a live demo with some simple Ansible code. I’m Luca Berton and welcome to today’s episode of Ansible Pilot.

Ansible enable user account

Today we’re talking about the Ansible module user. The full name is ansible.builtin.user, which means that is part of the collection of modules “builtin” with ansible and shipped with it. It’s a module pretty stable and out for years, it manages user accounts. It supports a huge variety of Linux distributions, SunOS and macOS, and FreeBSD. For Windows, use the module instead.


This module has many parameters to perform any task. The only required is “name”, which is the username. The parameter “state” allows us to create or delete a user. The “password_lock” parameter specifies to unlock the user password if locked. This parameter uses the passwd tool to change a password by changing it to a value that matches no possible encrypted value (it adds a ´!´ at the beginning of the password). To enable our user obviously we need to disable this parameter. The “shell” parameter specifies the user shell. Two very special are the nologin and false shell. Apply the value of “/bin/bash” is going to restore user access.


Let’s jump into a real-life Ansible Playbook to enable a user without password lock and with the appropriate shell.


- name: user module demo
  hosts: all
  become: true
    myuser: "example"
    - name: enable user
        name: "{{ myuser }}"
        state: present
        password_lock: false
        shell: "/bin/bash"


$ ansible-playbook -i demo/inventory enable\ user\ account/user.yml
PLAY [user module demo] ***************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: []
TASK [enable user] ********************************************************************************
changed: []
PLAY RECAP ****************************************************************************************           : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0


# getent passwd | grep example
example:x:1002:1002:Ansible example:/home/example:/bin/bash
# passwd -S example
example PS 2021-10-04 0 99999 7 -1 (Password set, SHA512 crypt.)
# grep example /etc/shadow

code with ❤️ in GitHub


Now you know how to enable a user without a password lock and with the appropriate shell. Subscribe to the YouTube channel, Medium, Website and Twitter to not miss the next episode of the Ansible Pilot.


Learn the Ansible automation technology with some real-life examples in my

My book Ansible By Examples: 100+ Automation Examples For Linux and Windows System Administrator and DevOps

Want to keep this project going? Please donate

Follow me

Subscribe not to miss any new releases

October 4, 2021

FREE Top 10 Best Practices

Top 10 Best Practices of Ansible Automation: save time, reduce errors and stress