我正在尝试提高 ansible 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
Run Code Online (Sandbox Code Playgroud)
运行这需要惊人的 57 秒。与执行相同操作的 bash 脚本相比:
测试文件
#!/bin/bash
touch /tmp/hello
for i in {1..500}
do
sh /home/admin/hello.sh
echo "This is iteration $i"
done
Run Code Online (Sandbox Code Playgroud)
你好.sh
#!/bin/bash
echo "Hello, World!" >> /tmp/hello
Run Code Online (Sandbox Code Playgroud)
这需要大约 1.5 秒才能运行。
我已经对ansible.cfg文件进行了一些更改
[ssh_connection]
ssh_args = -o ControlMaster=auto …Run Code Online (Sandbox Code Playgroud)