How to Accelerate Ansible playbook Speed

FoxuTech
2 min readMar 27, 2022

--

How to Accelerate Ansible playbook Speed: Anytime faced or observed, the ansible playbook executing for long time? Does that slowing your productivity or kept to wait for the result? Then it could be there is some configuration issue, or you may using default configuration. If you able to tweak the ansible configuration, it may reduce the time sometime ~10x, again please note some case we may should accept the timing, that may be intentional or actual time for execution. Let’s check how to How to increase the ansible playbook execution Speed.

Before we are starting, we should know ansible configuration file, By Default ansible configuration path:

/etc/ansible/ansible.cfg

If you think the default configuration was not used, you can identify the ansible configuration path via,

ansible@motoskia:~# ansible --version
ansible 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]

as a best practice’s recommendation, always take a backup if the config file, before you may the changes, this will be important if we need to roll-back the changes to any reason.

Fork:

You may see the number node execution may limited, that also one of the key reasons for slow. If you have more than 100 nodes, number the patch of 5 may take time to complete all the nodes. To improve that, fork is the one we should check in ansible configuration. The fork is the default parallel number of the process while communicating to remote nodes. The default value is 5. This number can be increased from 5 to 500 depends on the ansible node configuration.

ansible@motoskia:~# cat /etc/ansible/ansible.cfg | grep forks
forks = 25

I have set the number of forks to 25. You need to find out the exact value by re-running the job after changing the number of forks.

Strategies

Strategies are a way to control play execution. By default, plays run with a linear strategy, in which all hosts will run each task before any host starts the next task, using the number of forks (default 5) to parallelize.

The serial directive can ‘batch’ this behavior to a subset of the hosts, which then run to completion of the play before the next ‘batch’ starts.

Continue Reading on: How to Accelerate Ansible playbook Speed — FoxuTech

--

--

FoxuTech
FoxuTech

Written by FoxuTech

Discuss about #Linux, #DevOps, #Docker, #kubernetes, #HowTo’s, #cloud & IT technologies like #argocd #crossplane #azure https://foxutech.com/

No responses yet