执行流程-Ansible游戏如何运作? [英] Execution flow - How ansible play works?
问题描述
在以下计算机场景中:
我试图在文档中理解这一点: 默认情况下,Ansible会在所有受到播放影响的主机上运行每个任务,然后再使用5个分支在任何主机上开始下一个任务."
Am trying to understand this point in documentation: "By default, Ansible runs each task on all hosts affected by a play before starting the next task on any host, using 5 forks."
说,task1
是远程执行类型(不是本地执行类型)
Say, task1
is remote execution type(not local execution type)
如果play1
需要在所有4台主机(以上)上运行task1
,则
If play1
needs to run task1
on all 4 hosts(above), then
是否只能在执行后在host2
上执行task1
(在host1
上执行task1
并检索执行结果)?如何利用5个叉子?
Does ansible execute task1
on host2
only after executing (task1
on host1
and retrieve the result of execution)? How are 5 forks utilised?
注意:每次执行任务都应将JSON结果返回给ansible服务器.
推荐答案
Q:仅在执行之后(在host1上的task1并检索执行结果),才能在host2上执行task1吗?"
A:不.
问:如何利用5个叉子?"
A:默认情况下,Ansible在5台远程主机上并行运行播放.请参见设置货叉数.
A: By default, Ansible runs the play at 5 remote hosts in parallel. See Setting the number of forks.
Q:试图理解:默认情况下,Ansible在受游戏影响的所有主机上运行每个任务,然后在任何主机上开始下一个任务,..."
A:默认值为线性策略将同时执行每个任务",即所有分叉都必须先完成一项任务,然后才能移至下一个任务.有关其他策略,请参见插件列表.
A: The default is linear strategy "will execute each task at the same time" i.e. all forks must complete a task before moving to the next one. For other strategies see Plugin list.
Q:什么是锁步?"
A:锁步" 描述了线性策略,即所有分叉必须先完成一个任务(步骤),然后再移至下一个任务(分叉已锁定). 报价:
A: "Lockstep" describes the linear strategy i.e. all forks must complete a task(step) before moving to the next one(the forks are locked). Quoting:
锁步系统是容错计算机系统,可以同时并行运行同一组操作."
Q:什么是forks?这是一个python线程吗?"
A:否.Ansible fork不是python线程.引用自词汇表:
A: No. Ansible fork is not a python thread. Quoting from Glosary:
"Forks:Ansible与远程节点并行对话,可以通过传递--forks或在配置文件中编辑默认值来设置并行度.默认值为非常保守的五(5)个forks ,尽管如果您有大量的RAM,则可以轻松地将其设置为50之类的值,以提高并行度."
看看源代码.部分代码是线程化的.
Take a look at the source-code. Parts of the code are threaded.
$ grep -r "import threading" ansible
ansible/test/lib/ansible_test/_internal/thread.py:import threading
ansible/lib/ansible/galaxy/collection.py:import threading
ansible/lib/ansible/plugins/callback/cgroup_perf_recap.py:import threading
ansible/lib/ansible/plugins/callback/cgroup_memory_recap.py:import threading
ansible/lib/ansible/plugins/strategy/__init__.py:import threading
Q:"如何使用Python实现并行性?"
A:Ansible中的并行性由策略插件控制.例如 linear 插件:
A: The parallelism in Ansible is controlled by strategy plugins. For example the linear plugin:
按C(serial)(默认为全部)定义的主机批处理,任务执行处于锁步状态.主机的派生限制最多将同时执行每个任务,然后执行下一个主机系列,直到批处理完成,然后再继续执行下一个任务."
请参见线性插件
display.debug("building list of next tasks for hosts")
for host in hosts:
host_tasks[host.name] = iterator.get_next_task_for_host(host, peek=True)
...
display.debug("counting tasks in each state of execution")
host_tasks_to_run = [(host, state_task)
for host, state_task in iteritems(host_tasks)
if state_task and state_task[1]]
...
for (k, v) in host_tasks_to_run:
...
在类StrategyBase中处理结果是线程化的.
# create the result processing thread for reading results in the background
self._results_thread = threading.Thread(target=results_thread_main, args=(self,))
self._results_thread.daemon = True
self._results_thread.start()
这篇关于执行流程-Ansible游戏如何运作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!