【发布时间】:2017-12-03 05:47:53
【问题描述】:
鉴于以下剧本:
---
- name: test local_action with_items
hosts: localhost
gather_facts: false
tasks:
- name: "add something to a file"
shell: echo '{{item}}' >> foo.txt
with_items:
- "aaaaa"
- "aaaaa"
# using 40 items
或
---
- name: test local_action with_items
hosts: localhost
gather_facts: false
tasks:
- name: "add something to a file"
shell: echo '{{item}}' >> foo.txt
with_sequence: count=40
后一个剧本运行 5 秒。
Using a bash loop is obviously much(1000 倍)更快,耗时 5 毫秒:
time for i in $(seq 1 40); do echo $i >> foo.txt; done
现在很明显,Ansible 有一些开销,但有没有可能加快这个速度?
【问题讨论】:
-
Ansible 不应该是闪电般的速度,它应该是易于使用且舒适的。而且您通常使用 Ansible 将基础架构部署从几天缩短到几分钟,而不是将
echo-loops 从几分钟缩短到几秒。 -
@KonstantinSuvorov:当然可以,但是复杂的剧本可能包含许多
lineinfile条目,如果周转时间可以减少几分钟,它可能会很有用。如果这个循环需要 100 毫秒或 500 毫秒... -
我希望在您的示例中看到关键字
local_action
标签: ansible