I am trying to disable a user and give no login access to the user.

I am trying to disable a user and not remove it completely

I typically do something like:

  • name: Disable the ubuntu user
    user:
    name: ubuntu
    password: “!”
    shell: /usr/sbin/nologin

  • name: Remove the ubuntu users ssh key
    file:
    path: /home/ubuntu/.ssh/authorized_keys
    force: yes
    state: absent

Or you can just expire the user :

- user:
     name: thatguy
     expires: "{{lookup('pipe', 'date +%s')}}"

Thanks :slight_smile: It works!

Thanks. It works :slight_smile: