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. windwos API 第七篇 分离路径,组合路径 _splitpath _makepath

    函数原型: //Break a path name into components. void _splitpath( const char *path, char *drive, char *dir ...

  2. 解决wordpress 5.3更新后Uncaught Typeerror: $ is not a function

    本文不再更新,可能存在内容过时的情况,实时更新请移步原文地址:解决wordpress 5.3更新后Uncaught Typeerror: $ is not a function: 本文通过插件的办法解 ...

  3. leetcode 75 Sorted Colors

    两种解法 1)记录0和1的个数 然后按照记录的个数将0和1重新放入原数组,剩下的补2 2)双指针left,right left表示0~left-1都为0,即i之前都为0 right表示right+1~ ...

  4. 【agc019f】AtCoder Grand Contest 019 F - Yes or No

    题意 有n个问题答案为YES,m个问题答案为NO. 你只知道剩下的问题的答案分布情况. 问回答完N+M个问题,最优策略下的期望正确数. 解法 首先确定最优策略, 对于\(n<m\)的情况,肯定回 ...

  5. 左神算法书籍《程序员代码面试指南》——2_03删除链表的中间节点和a/b处的节点

    [题目]给定链表的头节点head,实现删除链表的中间节点的函数.例如:不删除任何节点:1->2,删除节点1:1->2->3,删除节点2:1->2->3->4,删除节 ...

  6. Java文件写入

    一,FileWritter写入文件 FileWritter, 字符流写入字符到文件.默认情况下,它会使用新的内容取代所有现有的内容,然而,当指定一个true (布尔)值作为FileWritter构造函 ...

  7. Spinrg WebFlux中Cookie的读写

    WebFLux与WebMvc的差异 WebFlux读写Cookie不像WebMvc那么直接,最主要的原因是WebMvc是基于Servlet规范的,而WebFlux仅仅遵守的是HTTP协议.所以在使用的 ...

  8. hadoop 轻松时刻 hdfs漫画

    hadoop漫画:

  9. TZOJ 3522 Checker Challenge(深搜)

    描述 Examine the 6x6 checkerboard below and note that the six checkers are arranged on the board so th ...

  10. Leetcode476.Number Complement数字的补数

    给定一个正整数,输出它的补数.补数是对该数的二进制表示取反. 注意: 给定的整数保证在32位带符号整数的范围内. 你可以假定二进制数不包含前导零位. 示例 1: 输入: 5 输出: 2 解释: 5的二 ...