CMDB Asset Acquisition

Source: Internet
Author: User
Tags unique id

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.