saltstack安装:略过

python脚本修改密码:

 # -*- coding utf-8 -*-
import socket
import re
import os
import sys
import crypt localIP = socket.gethostbyname(socket.gethostname()) def password():
localIP = socket.gethostbyname(socket.gethostname()) #获取本地ip
a = re.split('[.]', localIP) #切割ip地址并生成列表
addr = a[3]
ps = "Subuy2017@"+addr
return ps new_passwd = crypt.crypt(password(),"ab") #将生成的密码加密
change_passwd = "usermod -p %s test" %(new_passwd) #采用usermod方式修改密码,必须使用密文密码来修改
os.system(change_passwd)
print("Congratulation!,password for %s is %s " %(localIP,password()))
sys.exit()

结合以上脚本配合saltstack 命令来批量修改服务器密码:

 [root@testd files]# salt -N 'test' state.highstate
rac2:
----------
ID: file
Function: file.managed
Name: /usr/local/shell/change_passwd.py
Result: True
Comment: File /usr/local/shell/change_passwd.py updated
Started: 10:57:38.489545
Duration: 568.87 ms
Changes:
----------
diff:
---
+++
@@ -17,7 +17,7 @@
return ps new_passwd = crypt.crypt(password(),"ab")
-change_passwd = "usermod -p %s test" %(new_passwd)
+change_passwd = "usermod -p %s root" %(new_passwd)
os.system(change_passwd)
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
Result: True
Comment: Command "python /usr/local/shell/change_passwd.py" run
Started: 10:57:39.059976
Duration: 114.552 ms
Changes:
----------
pid:
19860
retcode:
0
stderr:
stdout:
Congratulation!,password for IP地址 is Subuy2017@162 Summary
------------
Succeeded: 2 (changed=2)
Failed: 0
------------
Total states run: 2
rac1:
----------
ID: file
Function: file.managed
Name: /usr/local/shell/change_passwd.py
Result: True
Comment: File /usr/local/shell/change_passwd.py updated
Started: 10:57:39.149359
Duration: 598.117 ms
Changes:
----------
diff:
---
+++
@@ -17,7 +17,7 @@
return ps new_passwd = crypt.crypt(password(),"ab")
-change_passwd = "usermod -p %s test" %(new_passwd)
+change_passwd = "usermod -p %s root" %(new_passwd)
os.system(change_passwd)
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
Result: True
Comment: Command "python /usr/local/shell/change_passwd.py" run
Started: 10:57:39.749030
Duration: 109.626 ms
Changes:
----------
pid:
720
retcode:
0
stderr:
stdout:
Congratulation!,password for IP地址 is Subuy2017@161 Summary
------------
Succeeded: 2 (changed=2)
Failed: 0
------------
Total states run: 2

saltstack+python批量修改服务器密码的更多相关文章

  1. Ansible playbook 批量修改服务器密码 先普通后root用户

    fsckzy   Ansible playbook 批量修改服务器密码 客户的需求:修改所有服务器密码,密码规则为Rfv5%+主机名后3位 背景:服务器有CentOS6.7,SuSE9.10.11,r ...

  2. Python脚本批量修改服务器密码

    搭建环境 centos 7.4 使用脚本 python 批量修改connect用户的密码 生成密码为随机密码 保存为xls文档   passwd_chang #!/usr/bin/env python ...

  3. Python自动批量修改服务器密码

    工作中,我们经常会定期更换服务器密码,如果手动去修改,不仅费时,而且容易出错.下面提供了一种思路,可以实现批量.自动修改服务器密码. 大致思路:首先,为每一台服务器设定一个唯一标识:其次,将每台服务器 ...

  4. python实现批量修改服务器密码

    需求:机房.线上有多台主机,为了保障安全,需要定期修改密码.若手动修改,费时费力易出错. 程序应该满足如下需求 : 1.在现有的excel密码表格,在最后一个字段后面生成新的密码,另存为一个新的exc ...

  5. python批量修改ssh密码

    由于工作需要本文主结合了excel表格,对表格中的ssh密码进行批量修改 以下是详细代码(python3): #!/usr/bin/env python#-*-coding:utf-8-*- impo ...

  6. ansible批量修改服务器密码

    看了一下网上代码大多数是ansible-playbook实现的,需要写一个脚本,或者手动传递变量进去. 以前用python tcp模块写过客户端主动上报修改密码脚本 今天写一个ansible主控客户端 ...

  7. Python 批量修改root密码

    #_*_coding:utf8_*_ from multiprocessing import Process, Pool import paramiko import sys,os host_list ...

  8. python批量修改linux主机密码

    +++++++++++++++++++++++++++++++++++++++++++标题:python批量修改Linux服务器密码时间:2019年2月24日内容:基于python实现批量修改linu ...

  9. 批量修改Linux密码脚本(Python)

    搭建环境 centos 7.4 使用脚本 python 批量修改connect用户的密码 生成密码为随机密码 保存为xls文档 #!/usr/bin/env python # -*- coding: ...

随机推荐

  1. [Bzoj3696]化合物【暴力+树形Dp】

    Online Judge:Bzoj3696 Label:暴力,树形Dp 题目描述 首长NOI惨跪,于是去念文化课了.现在,他面对一道化学题. 这题的来源是因为在一个奇怪的学校两个化竞党在玩一个奇怪的博 ...

  2. Luogu P2101 命运石之门的选择(分治+搜索)

    P2101 命运石之门的选择 题意 题目描述 在某一条不知名世界线的冈伦今天突然接到了一条\(dmail\),上面说世界线将会发生巨大变动,未来的他无论如何都无法扭转这种变动回到原来的世界线.而世界线 ...

  3. [转]Visual Studio 2010单元测试(3)--顺序单元测试

    之前我们做的测试都是一个一个进行的,当然我们也可以一次性选择多个测试方法进行,但是测试运行的顺序以“测试列表编辑器”窗口中的默认列表顺序为准.在实际场景中,我们需要进行有顺序的单元测试,步骤可能每一步 ...

  4. 微信audio自动播放(ios播放问题)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. nodejs + mySQL实践

    1.建立数据库连接:createConnection(Object)方法      该方法接受一个对象作为参数,该对象有四个常用的属性host,user,password,database.与php中 ...

  6. 软件-浏览器-GoogleChrome:Google Chrome

    ylbtech-软件-浏览器-GoogleChrome:Google Chrome Google Chrome是一款由Google公司开发的网页浏览器,该浏览器基于其他开源软件撰写,包括WebKit, ...

  7. SpringMVC配置顺序的问题

    1:web.xml:web应用一经加载,先来找他         1):指明applicationContext的位置         2):引入spring监听,ContextLoaderListe ...

  8. PAT甲级——A1043 Is It a Binary Search Tree

    A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...

  9. eclipse中运行java程序

    1 package ttt; public class Testttt { public static void main() { Person p =new Person(); p.name=&qu ...

  10. spring boot项目启动报DataSource错误

    初建一个简单的spring boot 项目,启动后会报错. Exception encountered during context initialization - cancelling refre ...