基本用法
ansible 10.0.0.11 -m user -a "name=sky01"
指定用户uid信息
anisble 10.0.0.11 -m user -a "name=sky02 uid=666"
指定用户组信息
ansible 10.0.0.11 -m user -a "name=sky03 group=sky02" ansible 10.0.0.11 -m user -a "name=sky04 groups=sky02"
批量创建虚拟用户
ansible 10.0.0.11 -m user -a "name=rsync create_home=no shell=/sbin/nologin"
给指定用户创建密码
ps:利用ansbile程序user模块设置用户密码信息,需要将明文信息转为密文信息进行设置
生成密文密码
ansible all -i localhost, -m debug -a "msg={{ '密码信息(123456)' | password_hash('sha512','加密效验信息(随便写)') }}"
-i localhost 在本地生成信息
-m debug 调试模块
sha512 加密方式
# ansible all -i localhost, -m debug -a "msg={{ '123456' | password_hash('sha512','sky01') }}"
localhost | SUCCESS => {
"msg": "$6$sky01$Ppe22caGxlbHwCR5biZ0oCcMa63McBIBgXD3RIkO080MckocOdUl2/SpKWUgPCdAOOE1Yjzyb5Oir2vgOjVwL/"
}
再去修改创建密码(-a 后面请使用单引号'')
# ansible 10.0.0.11 -m user -a 'name=sky01 password=$6$sky01$Ppe22caGxlbHwCR5biZ0oCcMa63McBIBgXD3RIkO080MckocOdUl2/SpKWUgPCdAOOE1Yjzyb5Oir2vgOjVwL/'
[WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work properly.
10.0.0.11 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"append": false,
"changed": true,
"comment": "",
"group": 1001,
"home": "/home/sky01",
"move_home": false,
"name": "sky01",
"password": "NOT_LOGGING_PASSWORD",
"shell": "/bin/bash",
"state": "present",
"uid": 1001
}