Create user with option --disabled-password by Ansible

前端 未结 2 1499
萌比男神i
萌比男神i 2021-02-15 13:37

On Ubuntu 14.04 I creating user with disabled password like:

sudo adduser --disabled-password myuser

I need to do same with Ansible

2条回答
  •  温柔的废话
    2021-02-15 14:12

    Since Ansible 2.6 the user module has the option password_lock, which will run usermod -L (Linux), pw lock (FreeBSD), or usermod -C (?):

    usermod -L:

    Lock a user's password. This puts a '!' in front of the encrypted password, effectively disabling the password.

    pw lock:

    The pw utility supports a simple password locking mechanism for users; it works by prepending the string *LOCKED* to the beginning of the password field in master.passwd to prevent successful authentication.

    So you could use:

    - name: Create password locked user
      user:
        name: myuser
        state: present
        password_lock: yes
    

提交回复
热议问题