我希望提高ansible playbook的性能。 我有一个测试playbook如下:
---
- name: Test
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Creating an empty file
file:
path: /tmp/hello
state: touch
- name: Test
command: "echo 'Hello, World!' >> /tmp/hello"
with_sequence: start=1 end=500
delegate_to: localhost
运行此操作需要长达57秒之久。与执行相同操作的bash脚本相比: < p> test.sh
#!/bin/bash
touch /tmp/hello
for i in {1..500}
do
sh /home/admin/hello.sh
echo "This is iteration $i"
done
hello.sh
#!/bin/bash
echo "Hello, World!" >> /tmp/hello
运行该程序需要约1.5秒钟。
我已经对ansible.cfg
文件进行了一些更改。
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=18000s -o PreferredAuthentications=publickey
control_path = %(directory)s/ansible-ssh-%%h-%%p-%%r
pipelining = True
有没有其他办法可以改善这种糟糕的表现?
shell: "for i in {1..500}; do echo 'Hello, World!' >> /tmp/hello; done"
。 - β.εηοιτ.βε