Paramiko
Import Paramiko Private_key = Paramiko. Rsakey.from_private_key_file ('/home/auto/.ssh/id_rsa ') # Create an SSH object SSH = Paramiko. Sshclient ()
# Allow connections to hosts that are not in the Know_hosts file Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())
# Connection Server Ssh.connect (hostname= ' Peng ', port=22, username= ' Peng ', Key=private_key) # Execute Command stdin, stdout, stderr = Ssh.exec_command (' df ')
# Get command results result = Stdout.read () # Close Connection Ssh.close () |
Saltstack
1. Installation and Configuration
Master
""" 1. Installing Salt-master Yum Install Salt-master 2. Modify the configuration file:/etc/salt/master interface:0.0.0.0 # Indicates the IP of master 3. Start Service Salt-master Start """ |
Minion:
""" 1. Installing Salt-minion Yum Install Salt-minion
2. Modify the configuration file/etc/salt/minion MASTER:192.168.1.100 # Master's address Or Master -192.168.1.4 -192.168.1.5 Random_master:true
Id:peng # The unique ID that the client displays in Salt-master 3. Start Service Salt-minion Start """ |
2. Authorization
Master
""" Salt-key-l # View authorized and unauthorized slave Salt-key-a salve_id # Accept the salve of the specified ID Salt-key-r salve_id # denies the salve of the specified ID salt-key-d salve_id # Delete The salve of the specified ID """ |
3. Execution of commands
To remotely operate the salve on the master server:
1) Shell-based command
Salt ' peng ' cmd.run ' ifconfig '
2) The Salt API-based approach
Import Salt.client
Local = Salt.client.LocalClient ()
result = Local.cmd (' Peng ', ' cmd.run ', [' ifconfig '])
This article is from a "a little" blog, make sure to keep this source http://pengai.blog.51cto.com/6326789/1977740
CMDB Asset Acquisition