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

11 views
Skip to first unread message

POOJA VENKATESH

unread,
Apr 12, 2018, 5:11:24 PM4/12/18
to ansible...@googlegroups.com

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

---
- hosts: target1
  tasks:
    - name: disable the user
      become: yes
      user:
        name: random
        group: sudo
        state: absent
 

When I run this playbook I see that the user is removed. Is there a way I can disable the user other than using expire parameter? I just want the user to stay but not have any login capabilities.


Matt Martz

unread,
Apr 12, 2018, 5:13:50 PM4/12/18
to ansible...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAAGG3SAX-Anb95ODx10xL21WoyzRN3VwWcogZwvrxweUowd5Qg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Brian Coca

unread,
Apr 12, 2018, 5:16:53 PM4/12/18
to Ansible Project
Or you can just expire the user :


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





--
----------
Brian Coca

POOJA VENKATESH

unread,
Apr 12, 2018, 5:59:17 PM4/12/18
to ansible...@googlegroups.com

POOJA VENKATESH

unread,
Apr 12, 2018, 6:00:28 PM4/12/18
to ansible...@googlegroups.com
Thanks. It works :)

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages