


Examples of methods used by ansible as a python module library
ansible is a python package, a complete unpack and play software. The only requirement for the client is to have ssh and python, and the python-simplejson package is installed. The deployment is ridiculously simple. The following article mainly introduces examples of methods for using ansible as a python module library. Friends in need can refer to it.
Preface
ansible is a new automated operation and maintenance tool. It is developed based on Python and integrates many operation and maintenance tools (puppet, cfengine, chef, func, fabric), it realizes functions such as batch system configuration, batch program deployment, and batch running of commands. Ansible works based on modules and does not have the ability to deploy in batches. What really has batch deployment is the module run by ansible, and ansible only provides a framework.
Mainly includes:
(1) Connection plugins: responsible for communicating with the monitored end;
(2) Host inventory : The specified operating host is the monitoring host defined in a configuration file;
(3) Various modules core modules, command modules, custom modules;
(4) Use plug-ins to complete functions such as recording log emails;
(5) Playbook: When the script performs multiple tasks, the node can run multiple tasks at one time if not necessary.
Ansible is a very good tool among operation and maintenance tools. I personally like it. The yml file can be flexibly configured according to the needs to achieve different business needs. Because there is no need to install a client, it is very easy to get started. In some cases, you may need to write ansible as a library component of python into your own script. Today's script will show how ansible is combined with a python script, that is, how to use ansible in a python script. We Unfold gradually.
Let’s look at the first example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
This example shows how we How to run system commands through ansible in a python script. Let's look at the second example and connect it to our yml file.
The content of the simple yml file is as follows:
1 2 3 4 |
|
The python script that calls the playbook is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
For more examples of methods using ansible as a python module library, please pay attention to the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

Fastapi ...

Using python in Linux terminal...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

About Pythonasyncio...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...

Loading pickle file in Python 3.6 environment error: ModuleNotFoundError:Nomodulenamed...

Discussion on the reasons why pipeline files cannot be written when using Scapy crawlers When learning and using Scapy crawlers for persistent data storage, you may encounter pipeline files...
