Saltstack+python Batch Modify server password

Source: Internet
Author: User
Tags crypt diff saltstack

Saltstack Installation: Skip

Python Script Change Password:

1 #-*-Coding Utf-8-*-2 ImportSocket3 ImportRe4 ImportOS5 ImportSYS6 ImportCrypt7 8 9Localip =Socket.gethostbyname (Socket.gethostname ())Ten  One defpassword (): ALocalip = Socket.gethostbyname (Socket.gethostname ())#获取本地ip -A = Re.split ('[.]', Localip)#切割ip地址并生成列表 -addr = a[3] thePS ="[email protected]"+Addr -     returnPS -  -new_passwd = crypt.crypt (password (),"AB") #将生成的密码加密 +CHANGE_PASSWD ="usermod-p%s Test"%(NEW_PASSWD) #采用usermod方式修改密码, you must use ciphertext password to modify - Os.system (CHANGE_PASSWD) + Print("Congratulation!,password for%s is%s"%(Localip,password ())) ASys.exit ()

Combine the above script with the Saltstack command to bulk modify the server password:

1[[email protected] files]#salt-n ' test ' state.highstate2 RAC2:3----------4 Id:file5 Function:file.managed6Name:/usr/local/shell/change_passwd.py7 result:true8comment:file/usr/local/shell/change_passwd.py Updated9started:10:57:38.489545Tenduration:568.87Ms One Changes: A---------- - diff: ---- the+++ -@@ -17,7 +17,7 @@ -                        returnPS -                     +new_passwd = crypt.crypt (password (),"AB") --CHANGE_PASSWD ="usermod-p%s Test"%(NEW_PASSWD) ++CHANGE_PASSWD ="usermod-p%s Root"%(NEW_PASSWD) A Os.system (CHANGE_PASSWD) at                    Print("Congratulation!,password for%s is%s"%(Localip,password ())) - sys.exit () ----------- - Id:pkg_install - Function:cmd.run -name:python/usr/local/shell/change_passwd.py in result:true -Comment:command"python/usr/local/shell/change_passwd.py"Run tostarted:10:57:39.059976 +duration:114.552Ms - Changes: the---------- * PID: $19860Panax Notoginseng Retcode: - 0 the stderr: + stdout: ACongratulation!,password forIP Address is[Email protected] the  + Summary ------------- $Succeeded:2 (changed=2) $ failed:0 ------------- -Total states Run:2 the Rac1: -----------Wuyi Id:file the Function:file.managed -Name:/usr/local/shell/change_passwd.py Wu result:true -comment:file/usr/local/shell/change_passwd.py Updated Aboutstarted:10:57:39.149359 $duration:598.117Ms - Changes: ----------- - diff: A--- ++++ the@@ -17,7 +17,7 @@ -                        returnPS $                     thenew_passwd = crypt.crypt (password (),"AB") the-CHANGE_PASSWD ="usermod-p%s Test"%(NEW_PASSWD) the+CHANGE_PASSWD ="usermod-p%s Root"%(NEW_PASSWD) the Os.system (CHANGE_PASSWD) -                    Print("Congratulation!,password for%s is%s"%(Localip,password ())) in sys.exit () the---------- the Id:pkg_install About Function:cmd.run thename:python/usr/local/shell/change_passwd.py the result:true theComment:command"python/usr/local/shell/change_passwd.py"Run +started:10:57:39.749030 -duration:109.626Ms the Changes:Bayi---------- the PID: the720 - Retcode: - 0 the stderr: the stdout: theCongratulation!,password forIP Address is[Email protected] the  - Summary the------------ theSucceeded:2 (changed=2) the failed:094------------ theTotal states Run:2

Saltstack+python Batch Modify server password

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.