Chapter 20. Making Ansible Go Even Faster

Once you start using Ansible on a regular basis, you’ll often find yourself wishing that your playbooks could run more quickly. This chapter presents strategies for reducing the time it takes Ansible to execute playbooks.

SSH Multiplexing and ControlPersist

If you’ve made it this far in the book, you know that Ansible uses SSH as its primary transport mechanism for communicating with servers. In particular, it uses the system SSH program by default.

Because the SSH protocol runs on top of the TCP protocol, when you make a connection to a remote machine with SSH, you need to make a new TCP connection. The client and server must negotiate this connection before you can actually start doing useful work. The negotiation takes a small amount of time, but it adds up if you have to do it many times, so it becomes a “penalty.”

When Ansible runs a playbook it makes many SSH connections, to do things such as copy over files and run modules. Each time Ansible makes a new SSH connection to a host, it has to pay this negotiation penalty.

OpenSSH is the most common implementation of SSH; if you are on Linux or macOS, it is almost certainly the SSH client you have installed on your local machine. OpenSSH supports an optimization called SSH multiplexing, also referred to as ControlPersist, which allows multiple SSH sessions to the same host to share the same TCP connection. This means that the TCP connection negotiation happens only the first time, thus ...

Get Ansible: Up and Running, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.