通过 Ansible 使用选项 --disabled-password 创建用户 [英] Create user with option --disabled-password by Ansible
问题描述
在 Ubuntu 14.04 上,我使用禁用的密码创建用户,例如:
On Ubuntu 14.04 I creating user with disabled password like:
sudo adduser --disabled-password myuser
sudo adduser --disabled-password myuser
我需要对 Ansible user 模块做同样的事情
I need to do same with Ansible user module
--禁用密码
缺少 Ansible 文档中的类似选项.有人可以帮助我,如何使用用户模块获得相同的结果?
Similiar option in Ansible documentation is missing. Could somebody help me, how can I get the same result with user module?
推荐答案
user 模块使用 useradd
命令幕后.
如果您省略 user
模块的 password
参数,ansible 将调用 useradd
而不使用 -p
标志.
useradd 状态的手册页:
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 密码
crypt(3) 返回的加密密码.默认是禁用密码.
-p, --password PASSWORD
The encrypted password, as returned by crypt(3). The default is to disable the password.
这正是 OP 所需要的.
This is exactly what is needed by OP.
adduser --disabled-password test1
和 - 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.
这篇关于通过 Ansible 使用选项 --disabled-password 创建用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!