How does SSH multiplexing (ControlPersist) speed up Ansible?
AdvancedConceptFundamentals and Architecture
Answer
Every task normally needs an SSH connection. With ControlMaster/ControlPersist, the first connection to a host opens a master socket that stays alive in the background, and later tasks reuse it, skipping the TCP handshake, key exchange and authentication.
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s
control_path_dir = ~/.ansible/cp
These are already the defaults for the ssh plugin. Watch out for long socket paths: the Unix socket path limit (about 104 chars) causes unix_listener: path too long errors on deep home dirs or long hostnames, so keep control_path_dir short.
More on Fundamentals and Architecture
What is Ansible and what problem does it solve?BeginnerWhat does "agentless" mean in Ansible?BeginnerWhat are the requirements for the control node?BeginnerWhat does a managed node need?BeginnerIs Ansible push-based or pull-based?BeginnerWalk through what happens when you run `ansible-playbook site.yml`.Intermediate