Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Ansible create a separate SSH Connection for each tasks inside a playbook [closed]

Tags:

ssh

ansible

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.

like image 967
Gaurav Parashar Avatar asked Jan 22 '18 15:01

Gaurav Parashar


People also ask

What is the relationship of Ansible to SSH?

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.

Which connection plugin does Ansible use to open the SSH session at the first task and closes it after all its running tasks are completed?

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.

What is SSH pipelining?

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.


1 Answers

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
like image 70
larsks Avatar answered Oct 01 '22 05:10

larsks