如题所述
import ansible.runner
runner = ansible.runner.Runner(
module_name='ping',
module_args='',
pattern='web*',
forks=10
)
datastructure = runner.run()
ansible.executor.task_queue_manager
è¿æ¯ansibleçä¸ä¸ªå é¨æ¨¡åï¼ansible/executor/task_queue_manager.pyï¼ãåå§åçæºç å¦ä¸ï¼
class TaskQueueManager:
'''
This class handles the multiprocessing requirements of Ansible by
creating a pool of worker forks, a result handler fork, and a
manager object with shared datastructures/queues for coordinating
work between all processes.
The queue manager is responsible for loading the play strategy plugin,
which dispatches the Play's tasks to hosts.
'''
def __init__(self, inventory, variable_manager, loader, options, passwords, stdout_callback=None, run_additional_callbacks=True, run_tree=False):self._inventory = inventoryself._variable_manager = variable_managerself._loader = loaderself._options = optionsself._stats = AggregateStats()self.passwords = passwordsself._stdout_callback = stdout_callbackself._run_additional_callbacks = run_additional_callbacksself._run_tree = run_treeself._callbacks_loaded = Falseself._callback_plugins = []self._start_at_done = Falseself._result_prc = Noneâ¦â¦
å建æ¶ï¼éè¦ç主è¦åæ°å æ¬ï¼
inventory --> ç±ansible.inventory模åå建ï¼ç¨äºå¯¼å ¥inventoryæ件
variable_manager --> ç±ansible.vars模åå建ï¼ç¨äºåå¨åç±»åéä¿¡æ¯
loader --> ç±ansible.parsing.dataloader模åå建ï¼ç¨äºæ°æ®è§£æ
options --> åæ¾åç±»é 置信æ¯çæ°æ®åå ¸
passwords --> ç»å½å¯ç ï¼å¯è®¾ç½®å å¯ä¿¡æ¯
stdout_callback --> åè°å½æ°
ansible.playbook.play
ansible.playbookæ¯ä¸ä¸ªåç模åï¼æ¢ç¨äºCLIä¹ç¨äºAPIãä»æºç å¯ä»¥çåºæ¥ï¼
try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
ansible.playbook.playï¼ansible/playbook/play.pyï¼ãåå§åæºç çä»ç»å¦ä¸ï¼
__all__ = ['Play']
class Play(Base, Taggable, Become):
"""
A play is a language feature that represents a list of roles and/or
task/handler blocks to execute on a given set of hosts.
Usage:
Play.load(datastructure) -> Play
Play.something(...)
"""
æåï¼ç¨task_queue_manager(play)æ¥æ§è¡ï¼èè§ç©ï¼æºç çå®æ¹è§£éã
def run(self, play):'''Iterates over the roles/tasks in a play, using the given (or default)strategy for queueing tasks. The default is the linear strategy, whichoperates like classic Ansible by keeping all hosts in lock-step witha given task (meaning no hosts move on to the next task until all hostsare done with the current task).'''
runner = ansible.runner.Runner(
module_name='ping',
module_args='',
pattern='web*',
forks=10
)
datastructure = runner.run()
ansible.executor.task_queue_manager
è¿æ¯ansibleçä¸ä¸ªå é¨æ¨¡åï¼ansible/executor/task_queue_manager.pyï¼ãåå§åçæºç å¦ä¸ï¼
class TaskQueueManager:
'''
This class handles the multiprocessing requirements of Ansible by
creating a pool of worker forks, a result handler fork, and a
manager object with shared datastructures/queues for coordinating
work between all processes.
The queue manager is responsible for loading the play strategy plugin,
which dispatches the Play's tasks to hosts.
'''
def __init__(self, inventory, variable_manager, loader, options, passwords, stdout_callback=None, run_additional_callbacks=True, run_tree=False):self._inventory = inventoryself._variable_manager = variable_managerself._loader = loaderself._options = optionsself._stats = AggregateStats()self.passwords = passwordsself._stdout_callback = stdout_callbackself._run_additional_callbacks = run_additional_callbacksself._run_tree = run_treeself._callbacks_loaded = Falseself._callback_plugins = []self._start_at_done = Falseself._result_prc = Noneâ¦â¦
å建æ¶ï¼éè¦ç主è¦åæ°å æ¬ï¼
inventory --> ç±ansible.inventory模åå建ï¼ç¨äºå¯¼å ¥inventoryæ件
variable_manager --> ç±ansible.vars模åå建ï¼ç¨äºåå¨åç±»åéä¿¡æ¯
loader --> ç±ansible.parsing.dataloader模åå建ï¼ç¨äºæ°æ®è§£æ
options --> åæ¾åç±»é 置信æ¯çæ°æ®åå ¸
passwords --> ç»å½å¯ç ï¼å¯è®¾ç½®å å¯ä¿¡æ¯
stdout_callback --> åè°å½æ°
ansible.playbook.play
ansible.playbookæ¯ä¸ä¸ªåç模åï¼æ¢ç¨äºCLIä¹ç¨äºAPIãä»æºç å¯ä»¥çåºæ¥ï¼
try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
ansible.playbook.playï¼ansible/playbook/play.pyï¼ãåå§åæºç çä»ç»å¦ä¸ï¼
__all__ = ['Play']
class Play(Base, Taggable, Become):
"""
A play is a language feature that represents a list of roles and/or
task/handler blocks to execute on a given set of hosts.
Usage:
Play.load(datastructure) -> Play
Play.something(...)
"""
æåï¼ç¨task_queue_manager(play)æ¥æ§è¡ï¼èè§ç©ï¼æºç çå®æ¹è§£éã
def run(self, play):'''Iterates over the roles/tasks in a play, using the given (or default)strategy for queueing tasks. The default is the linear strategy, whichoperates like classic Ansible by keeping all hosts in lock-step witha given task (meaning no hosts move on to the next task until all hostsare done with the current task).'''
温馨提示:答案为网友推荐,仅供参考