If I have multiple tasks defined in my playbook, does ansible creates a separate ssh connection for each of the tasks. If yes, is that not a performance issue.
Because whenever I do a verbose o/p while i run the playbook, against each task i spot this. "ESTABLISH SSH CONNECTION FOR USER: gparasha" Am i wrong in my understanding.
Ansible relies on SSH for executing commands against remote Linux hosts. That means in order to leverage Ansible, you must configure this SSH access for the software such that you can overcome a password prompt automatically. Some less experienced Linux users may be intimidated by this prospect.
By default, Ansible ships with several connection plugins. The most commonly used are the paramiko SSH, native ssh (just called ssh), and local connection types. All of these can be used in playbooks and with /usr/bin/ansible to decide how you want to talk to remote machines.
Pipelining is the modern Ansible method of speeding up your ssh connections across the network to the managed hosts. It replaces the former Accelerated Mode. It reduces the number of ssh operations required to execute a module by executing many Ansible modules without an actual file transfer.
By default, Ansible creates a new connection for each task. It takes advantage of SSH connection multiplexing to significantly reduce the amount of time required to establish a new connection.
If you enable the pipelining feature, then in many cases Ansible will be able to re-use a single ssh connection for multiple tasks (although in some cases it will still need to spawn a new connection).
To enable pipelining, you need the following in your ansible.cfg
:
[ssh_connection]
pipelining = True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With