Ansible Code Analysis first--Main file-ansible analysis

Source: Internet
Author: User

February 23, 2016, learn, analyze Ansible code

Ansible is a tool for bulk deployment used in operations, which is itself a framework, specific deployment and architectural analysis, and the following article is good.

Http://os.51cto.com/art/201409/451927_all.htm

First analyze the main file ansible, and the code and comments are as follows:

1. from __future__ Import (Absolute_import, Division, print_function) 2, __metaclass__ = type3, __requires__ = ['ansible']

The first line introduces 3 modules, the role of which is as follows

Absolute_import using relative or absolute paths to import modules, refer to this article: http://taoyh163.blog.163.com/blog/static/1958035620074111276292/

Division Precision Division, refer to this article: http://www.cnblogs.com/feixingfei/archive/2011/12/18/2297596.html

Print_function Print function

The __future__ in this line is the Python syntax, which is explained as follows:

Python provides the __future__ module to import the next new version of the feature into the current version, so we can test some of the features of the new version in the current version. See:

Http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/ 001386820023084e5263fe54fde4e4e8616597058cc4ba1000

The second line feels very complicated to explain, and you can refer to this article:

Http://www.cnblogs.com/huangcong/archive/2011/08/28/2156307.html Part 3.2

The third line is to judge the dependent libraries, and the dependent files are all under the Ansible directory.

Try
    Import Pkg_resources
Except Exception:
    Pass

The original code is explained in English, said to introduce the package to ensure that the library version and path of accuracy, temporarily so understand it.

Import OS
Import Sys
Import Traceback
From ansible.errors import Ansibleerror, Ansibleoptionserror, Ansibleparsererror
From Ansible.utils.display Import display
From Ansible.utils.unicode import To_unicode

The introduction of common packages

Class LastResort (object):
    def display (self, msg):
        Print (MSG, file=sys.stderr)
    def error (self, MSG, wrap_text=none):
        Print (MSG, file=sys.stderr)

A class is defined, and the result is sorted by the final output.

Ansible Code Analysis first--Main file-ansible analysis

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.