Ansible is an open-source IT automation tool for continuous deployments or zero downtime rolling updates, software deployment, configuration management, and orchestration of more advanced IT tasks. Ansible minimizes the workloads and saves a lot of time during server configuration and application deployment.

In some scenarios we do have to maintain a large number of servers at a time then, on executing ansible-playbook it might take a longer time to finish up the playbook tasks. According to ansible official documentation, we can accelerate its playbook speed using various methods which we will be discussing in this article. Using these methods we can reduce the huge ratio of its actual time consumption by changing the ansible configuration.

Pipelining

Pipelining replaces the accelerated mode that was used in the earlier version of ansible which helps in speeding up ssh connection across the dedicated host. Ansible initiates many ssh connections to perform each playbook task, which may raise total time consumption. Pipelining is disabled by default, so when pipelining is enabled many Ansible modules are executed without an actual file transfer which reduces the number of ssh connections needed. The STDIN channel is used to pass the instruction to the known host during the module execution.

You must set the pipelining value to true in order to enable the pipelining in the ansible.cfg file.

How to speed-up an Ansible Playbook linux shell

Free Strategy

Ansible always executes the playbook in linear strategies which is one of the playbook’s workflows. During linear strategy, each task in the playbook is only started after every host finishes the particular task which is time-consuming.

Using a free strategy, all the hosts will be independent of each other where tasks on each host will continue without waiting for another host to complete the task. This helps in reducing the waiting time to complete the task on all dedicated hosts. To override the default strategy, set the strategy to free in your playbook YAML file.

How to speed-up an Ansible Playbook linux shell

Increase Number of Forks

Forks are used in remote hosts where a specific number of parallel processes provided by default configuration are executed when communicating with remote hosts. Fork determines the number of hosts to be configured at a time, the default is 5. The higher the fork number the faster you can finish up the task if you have a large number of remote hosts. We can limit the fork value according to your control machine capabilities such as memory available and network bandwidth.

You can override the default value by changing the fork value in the ansible.cfg file in the following way. In my case, I have set the fork value to 20.

How to speed-up an Ansible Playbook linux shell

Disable Facts Gathering

When we execute the ansible-playbook, different information about the host such as network connectivity, device information, system information, etc is gathered by the ansible and stored in the local memory cache on the control machine. If you are working on a large number of remote hosts, disabling the fact-gathering will save a lot of time as long as you don’t need them. You can’t disable fact gathering if you have used the ansible variable in the playbook.

How to speed-up an Ansible Playbook linux shell Advertisement

Conclusion

Ansible is one of the best automation tools but even better when it has enhanced speed. This article shows how we can boost ansible-playbook speed which helps fast server configuration and deployment in a simple and efficient way.