Use of the ssh-Based Cluster O & M tool ansible api [class saltstack]

Source: Internet
Author: User
Tags ansible modules saltstack


For saltstack users, Ansible is a good ssh-based solution. It can greatly simplify the automatic configuration management and process control methods of Unix administrators. It uses the push method to configure the customer system so that all work can be done on the master server side. Its command line mechanism is also very powerful, and you can use the Web UI to implement authorization management and configuration, of course, free of charge is very limited.

Well-known Ansible users include Fedora, Rackspace, Evernote, etc.

His ui looks like saltstack!

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140207/215555OS-0.jpg "title =" QQ20140122101917.png "alt =" wKiom1LfKy-gx1ynAALOWaWDXbs219.jpg "/>


Original article: http://rfyiamcool.blog.51cto.com/1030776/1353618


In my personal understanding, ansible is a good east for small environments. Ansible and other tools are now working on tri in China.


Today, python is prevalent. I think many people have developed a set of platform tools for the company or myself, and I have developed a set of front-end and back-end code, the combination of paramiko bootstrap tornado gevent redis is used, but the performance bottleneck will occur after the production.


Even if we were not satisfied with the performance and configuration management of the task queue, we were doing rabbitmq well. We didn't have thousands of servers in our department, so we could use the performance of our platform at that time.


However, to a certain extent, we can say that ansible is more stable than saltstack. After all, zeromq is too fast to discard data checks. Of course, if you use rabbitmq for data stability, but the performance is xx again, openstack may sometimes cause bottlenecks in communication queues due to rabbitmq.


However, paramiko crashes the module in the case of multiple threads.



Summarized the reasons for dissatisfaction at the time,

First, the current python level was not very low.

Second, gevent and paramiko are not perfectly integrated.

Third, there were no python tools available for reference at the time.


Let's leave it alone. In terms of ansible interfaces, because of the O & M platform, it is hard to solve the problem of having at least APIs to focus on tools.


In other words, ansible and saltstack are very similar. Apart from their processing models, one is paramilo-based and the other is zeromq's pubsub. In terms of configuration, ansible has a playbook, which is similar to the state of saltstack. Ansible is also the mode of yaml and jinja2.


I will not talk about the installation and configuration of ansible.


Install ansible tool yum install ansible to configure ip information vim/etc/ansible/hosts to generate keyssh-keygen-rcopykey, use ssh-copy-id xxxx to check who is alive ansible all-m pingansible all-m ping-u root to define the group, like saltstack, cat/etc/ansible/hosts [lvs-sh] 10.2.20.11110.2.20.20.10.2.20.1115



import ansible.runnerrunner = ansible.runner.Runner(   module_name='ping',   module_args='',   pattern='lvs-bj-*',   forks=10)datastructure = runner.run()



I believe that those who have used the saltstack api can definitely see the East ansible api .... Because they really look like!


Module_name = 'ping' # Here is the module name. I have read the list of ansible modules. Because it is written in python, you can also customize your own modules!

Module_args = ''# parameters, you know

Pattern = 'lvs-bj-* '# host matching

Forks = 10 # fork? Don't read it wrong. It's fork... Fork process!


If you don't have ansible, check out my steps ~ I can't connect to the testing virtual machine today, so I will temporarily run a configuration test on my machine.


650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140207/2155552962-1.jpg "style =" float: none; "title =" an1.jpg "alt =" wKioL1LfMDuTP5RaAAYT_ryKcFE108.jpg "/>


Key is required here! Since this tool is used, we should not feel the trouble!


650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140207/2155553259-2.jpg "style =" float: none; "title =" an2.jpg "alt =" wKiom1LfMF-AwcqTAAQjkIFw3bU578.jpg "/>


Test who is alive and execute w command.


650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140207/2155553405-3.jpg "style =" float: none; "title =" an3.jpg "alt =" wKioL1LfMDzzD1V3AAaw1RY6_B0618.jpg "/>



The official website provides a detailed example:


Really nothing, like saltstack, but call module and encapsulate it as json to return results)

#!/usr/bin/pythonimport ansible.runnerimport sys# construct the ansible runner and execute on all hostsresults = ansible.runner.Runner(    pattern='*', forks=10,    module_name='command', module_args='/usr/bin/uptime',).run()if results is None:   print "No hosts found"   sys.exit(1)print "UP ***********"for (hostname, result) in results['contacted'].items():    if not 'failed' in result:        print "%s >>> %s" % (hostname, result['stdout'])print "FAILED *******"for (hostname, result) in results['contacted'].items():    if 'failed' in result:        print "%s >>> %s" % (hostname, result['msg'])print "DOWN *********"for (hostname, result) in results['dark'].items():    print "%s >>> %s" % (hostname, result)


A simple shell command execution module


#!/usr/bin/env python#coding:utf-8import subprocessimport jsonimport os,sysspace = []df= os.popen('df -P -k').read()df = subprocess.Popen(["df", "-P", "-k"], stdout=subprocess.PIPE)output = df.communicate()[0]for line in output.split("\n")[1:]:    if len(line):        try:            device, size, used, available, percent, mountpoint = line.split()            space.append(dict(mountpoint=mountpoint, available=available))        except:            passprint json.dumps(dict(space=space), indent=4)




Summary:

This is okay. It can be used. It can complement puppet chef saltstack. During this time, I saw a lot of foreign O & M automation and platform talk. I found that ansible seems to be more widely used than saltstack in a foreigner's circle. After reading the article by a foreigner, he said that there are many old machines in their company, and no one dares to change, it seems that O & M automation is slowly advancing in many foreign companies, not as crazy as we think.


This article is from "Fengyun, it's her ." Blog, declined to reprint!

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.