SSH
Categories:
2 minute read
When you run an Ansible command or playbook, it establishes an SSH connection to each target host using the SSH protocol. Ansible uses SSH as a secure and reliable remote access and file transfer protocol. The SSH protocol is also supported by almost all modern operating systems and network devices, making it a universal method for remote access.
When Ansible establishes an SSH connection to a remote host, it authenticates using either a password or an SSH key pair. By default, Ansible uses SSH keys for authentication because they provide more robust security and are more convenient for automation. Ansible stores SSH keys in its inventory file, which allows it to authenticate with remote hosts without prompting for passwords.
Once the SSH connection is established, Ansible uses a Python-based module to execute commands or scripts on the remote host. These modules are uploaded to the remote host and executed in a temporary directory, which is then deleted after the module has completed.
Pipelining
Ansible uses pipelining to improve the performance of its playbooks. Pipelining allows Ansible to execute multiple tasks on a remote host using a single SSH session instead of establishing a new SSH connection for each job. This reduces the overhead of establishing new connections and can significantly speed up the execution of playbooks.
By default, pipelining is disabled in Ansible, but it can be enabled by setting the pipelining option to True in the ansible.cfg file or by passing the -f option on the command line. When pipelining is enabled, Ansible sends multiple tasks to the remote host in a single SSH session and executes them sequentially.
Pipelining can be especially useful when running playbooks that involve a large number of tasks or when running playbooks on slow or high-latency networks. However, it may not always be appropriate for certain tasks or environments, and it may require additional configuration or testing to ensure it works correctly in your environment.