使用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 用户模块
I need to do same with Ansible user module
-禁用密码
--disabled-password
Ansible文档中的类似选项丢失.有人可以帮助我,我如何通过用户模块获得相同的结果?
Similiar option in Ansible documentation is missing. Could somebody help me, how can I get the same result with user module?
推荐答案
用户模块使用useradd
命令在后台.
如果省略user
模块的password
参数,则不带-p
标志的ansible调用useradd
.
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所需要的.
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屋!