Ansible Automation (3)

Source: Internet
Author: User

Batch execution playbooks

Another way of remote batch command execution is to use playbooks;
This is Playbooks's Official document: http://docs.ansible.com/playbooks.html
Here are playbooks examples of ansible: https://github.com/ansible/ansible-examples

Using the Ansbile API in Python

The above methods of executing the Ansible module are called directly on the command line, and if further processing is required for the returned results, the Ansible module can be used in the program through API calls:
For example, the above method calls the scripts module in the command line in the API call:

import ansible.runnerresults = ansible.runner.Runner(pattern=‘myservers‘, forks=5,module_name=‘script‘, module_args=‘/opt/app/target.sh‘,).run()

Here is a detailed example of the official given, run directly, the result will be printed out, there will be an intuitive understanding:

#!/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"   

Ansible Automation (3)

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.