nainai1 发表于 2018-1-3 17:55:25

saltstack+python批量修改服务器密码

1 # salt -N 'test' state.highstate  
2 rac2:
  
3 ----------

  
4          >  
5   Function: file.managed
  
6         Name: /usr/local/shell/change_passwd.py
  
7       Result: True
  
8      Comment: File /usr/local/shell/change_passwd.py updated
  
9      Started: 10:57:38.489545
  
10   Duration: 568.87 ms
  
11      Changes:
  
12               ----------
  
13               diff:
  
14                   ---
  
15                   +++
  
16                   @@ -17,7 +17,7 @@
  
17                        return ps
  
18
  
19                  new_passwd = crypt.crypt(password(),"ab")
  
20                   -change_passwd = "usermod -p %s test" %(new_passwd)
  
21                   +change_passwd = "usermod -p %s root" %(new_passwd)
  
22                  os.system(change_passwd)
  
23                  print("Congratulation!,password for %s is %s " %(localIP,password()))
  
24                  sys.exit()
  
25 ----------

  
26          >  
27   Function: cmd.run
  
28         Name: python /usr/local/shell/change_passwd.py
  
29       Result: True
  
30      Comment: Command "python /usr/local/shell/change_passwd.py" run
  
31      Started: 10:57:39.059976
  
32   Duration: 114.552 ms
  
33      Changes:
  
34               ----------
  
35               pid:
  
36                   19860
  
37               retcode:
  
38                   0
  
39               stderr:
  
40               stdout:
  
41                   Congratulation!,password for IP地址 is Subuy2017@162
  
42
  
43 Summary
  
44 ------------
  
45 Succeeded: 2 (changed=2)
  
46 Failed:    0
  
47 ------------
  
48 Total states run:   2
  
49 rac1:
  
50 ----------

  
51          >  
52   Function: file.managed
  
53         Name: /usr/local/shell/change_passwd.py
  
54       Result: True
  
55      Comment: File /usr/local/shell/change_passwd.py updated
  
56      Started: 10:57:39.149359
  
57   Duration: 598.117 ms
  
58      Changes:
  
59               ----------
  
60               diff:
  
61                   ---
  
62                   +++
  
63                   @@ -17,7 +17,7 @@
  
64                        return ps
  
65
  
66                  new_passwd = crypt.crypt(password(),"ab")
  
67                   -change_passwd = "usermod -p %s test" %(new_passwd)
  
68                   +change_passwd = "usermod -p %s root" %(new_passwd)
  
69                  os.system(change_passwd)
  
70                  print("Congratulation!,password for %s is %s " %(localIP,password()))
  
71                  sys.exit()
  
72 ----------

  
73          >  
74   Function: cmd.run
  
75         Name: python /usr/local/shell/change_passwd.py
  
76       Result: True
  
77      Comment: Command "python /usr/local/shell/change_passwd.py" run
  
78      Started: 10:57:39.749030
  
79   Duration: 109.626 ms
  
80      Changes:
  
81               ----------
  
82               pid:
  
83                   720
  
84               retcode:
  
85                   0
  
86               stderr:
  
87               stdout:
  
88                   Congratulation!,password for IP地址 is Subuy2017@161
  
89
  
90 Summary
  
91 ------------
  
92 Succeeded: 2 (changed=2)
  
93 Failed:    0
  
94 ------------
  
95 Total states run:   2
页: [1]
查看完整版本: saltstack+python批量修改服务器密码