Ansible-playbook API

Source: Internet
Author: User
Tags dataloader

Import OS
Import Sys
Import Ansible
From collections Import Namedtuple

From Ansible.parsing.dataloader Import Dataloader
From Ansible.vars import Variablemanager
From Ansible.inventory Import Inventory
From Ansible.executor.playbook_executor import Playbookexecutor

def playbook_action (Playbook, hosts):
Variable_manager = Variablemanager ()
Loader = Dataloader ()
Inventory = ansible.inventory.Inventory (Loader=loader,variable_manager=variable_manager)
Inventory.clear_pattern_cache ()
options = namedtuple (' Options ', [' listtags ', ' listtasks ', ' listhosts ', ' syntax ', ' connection ', ' module_path ', ' Forks ', ' Remote_user ', ' private_key_file ', ' Ssh_common_args ', ' Ssh_extra_args ', ' Sftp_extra_args ', ' Scp_extra_args ', ' become ' , ' Become_method ', ' become_user ', ' verbosity ', ' check ')
options = Options (Listtags=false, Listtasks=false, Listhosts=false, syntax=false, connection= ' ssh ', Module_path=none, forks=100, Remote_user=none, Private_key_file=none, Ssh_common_args=none, Ssh_extra_args=none, Sftp_extra_args=None , Scp_extra_args=none, Become=none, Become_method=none, Become_user=none, Verbosity=none, Check=False)
Variable_manager.extra_vars = {' Host ': Hosts}
passwords = {}
Pbex = Playbookexecutor (Playbooks=[playbook], inventory=inventory, Variable_manager=variable_manager, Loader=loader , Options=options, Passwords=passwords)
Pbex.run ()

Ansible-playbook API

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.