基本用法
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 }