
1.利用python程序生成sha512加密密码Command:python -c 'import crypt,getpass;pw="test";print(crypt.crypt(pw))'[root@cent79-2 ~]# python -c 'import crypt,getpass;pw="test";print(crypt.crypt(pw))' $6$SU7Mzt1FAW63QD08$LYBib22jotPJMA7IsYEmESjVmQkoKSvXMdh6vt0LqewMw/tQOwe3nfbeEEHW3cEtaJwPUcv1d429O587RfUNU0 #pw="test",test为待设置的用户密码2.使用ansible user模块创建用户Command(ansible server端执行):ansible all -m user -a 'name=test home=/home/test password=$6$SU7Mzt1FAW63QD08$LYBib22jotPJMA7IsYEmESjVmQkoKSvXMdh6vt0LqewMw/tQOwe3nfbeEEHW3cEtaJwPUcv1d429O587RfUNU0'[root@cent79-2 ~]# ansible all -m user -a 'name=test home=/home/test password=$6$SU7Mzt1FAW63QD08$LYBib22jotPJMA7IsYEmESjVmQkoKSvXMdh6vt0LqewMw/tQOwe3nfbeEEHW3cEtaJwPUcv1d429O587RfUNU0' 192.168.10.100 | CHANGED = { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "comment": "", "create_home": true, "group": 1001, "home": "/home/test", "name": "test", "password": "NOT_LOGGING_PASSWORD", "shell": "/bin/bash", "state": "present", "stderr": "useradd: warning: the home directory already exists.\nNot copying any file from skel directory into it.\nCreating mailbox file: File exists\n", "stderr_lines": [ "useradd: warning: the home directory already exists.", "Not copying any file from skel directory into it.", "Creating mailbox file: File exists" ], "system": false, "uid": 1001 } [root@cent79-2 ~]#3.验证Client:[root@patrolagent home]# ls patrol test [root@patrolagent home]# [root@patrolagent home]# cat /etc/shadow |grep test test:$6$SU7Mzt1FAW63QD08$LYBib22jotPJMA7IsYEmESjVmQkoKSvXMdh6vt0LqewMw/tQOwe3nfbeEEHW3cEtaJwPUcv1d429O587RfUNU0:20609:0:99999:7::: [root@patrolagent home]#