Create user with option --disabled-password by Ansible

自古美人都是妖i 提交于 2019-12-04 22:11:09

问题


On Ubuntu 14.04 I creating user with disabled password like:

sudo adduser --disabled-password myuser

I need to do same with Ansible user module

--disabled-password

Similiar option in Ansible documentation is missing. Could somebody help me, how can I get the same result with user module?


回答1:


user module use useradd command under the hood.
If you omit password parameter for user module, ansible calls useradd without -p flag.
Man page of useradd states:

-p, --password PASSWORD
The encrypted password, as returned by crypt(3). The default is to disable the password.

This is exactly what is needed by OP.

Comparison of adduser --disabled-password test1 and - user: name=test2 state=present:

# grep test /etc/shadow
test1:*:17031:0:99999:7:::
test2:!:17031:0:99999:7:::
# passwd -S test1
test1 L 08/18/2016 0 99999 7 -1
# passwd -S test2
test2 L 08/18/2016 0 99999 7 -1

As you see in both cases passwords are locked.



来源:https://stackoverflow.com/questions/39013796/create-user-with-option-disabled-password-by-ansible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!