Paramiko
1 ImportParamiko2 3Private_key = Paramiko. Rsakey.from_private_key_file ('/home/auto/.ssh/id_rsa')4 5 #To create an SSH object6SSH =Paramiko. Sshclient ()7 #allow connections to hosts that are not in the Know_hosts file8 Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())9 #connecting to a serverTenSsh.connect (hostname='c1.salt.com', Port=22, Username='Wupeiqi', key=Private_key) One A #Execute Command -stdin, stdout, stderr = Ssh.exec_command ('DF') - #Get command Results theresult =Stdout.read () - - #Close Connection - ssh.close () + -Paramiko
Saltstack
1. Installation and Configuration
1 """ 2 1. Install Salt-master 3 yum install salt-master 42. Modify the configuration file:/etc/salt/master 5 interface:0.0.0.0 63. Start up 7 Service Salt-master start 8 "" 9 Master
1 """2 1. Installing Salt-minion3 Yum Install salt-minion4 5 2. Modify the configuration file/etc/salt/minion6 master:10.211.55.4 # Master's address7 or8 Master:9 -10.211.55.4Ten -10.211.55.5 One random_master:true A - Id:c2.salt.com # The unique ID that the client displays in Salt-master - 3. Start the Service salt-minion Start - """ - -Slave
2. Authorization
1 """ 2 salt-key-l # View authorized and unauthorized slave3salt-key-a salve_id # Accept Salve 4 of the specified ID salt-key-r salve_id # Deny salve5salt-key-d salve_id # of the specified ID Delete Salve6"""78 Master with the specified ID
3. Execution of commands
Remote operation of the salve on the master server
1Salt'c2.salt.com'Cmd.run'ifconfig'
Equivalent to Python:2 Importsalt.client3Local =salt.client.LocalClient ()4result = Local.cmd ('c2.salt.com','Cmd.run', ['ifconfig'])
CMDB Asset Management Acquisition