Chapter 41: SSH with Ansible and Terraform
In this chapter, you'll learn how Ansible uses SSH for agentless automation, how to configure SSH for Ansible inventory, and how Terraform uses SSH provisioners for infrastructure bootstrapping.
In the previous chapter, you learned how SSH is used in CI/CD pipelines with GitHub Actions, GitLab CI, and Jenkins.
You also saw how to manage SSH secrets, configure deploy keys, clean up keys if a deployment fails, and deploy to multiple servers in parallel using a matrix strategy. With that, you completed the CI/CD automation section of Module 11.
In this chapter, you'll learn how two popular infrastructure tools, Ansible and Terraform, use SSH. Although both rely on SSH, they use it for very different purposes.
Ansible is an agentless configuration management tool that doesn't require you to install any agent on the remote servers. Instead, it connects to them directly over SSH.
Every playbook, ad-hoc command, and role runs through an SSH connection. Once you understand how Ansible uses SSH, you'll be able to configure it correctly, troubleshoot connection problems, and secure your automation.
Terraform uses SSH in a much more limited way. Its main job is to create and manage infrastructure, not configure it. However, it can use SSH through provisioners to perform initial setup on newly created servers.
Understanding when Terraform uses SSH and when it doesn't will help you avoid many common infrastructure mistakes.