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