It’s not surprising that developers and engineers tend to become tribalist with operating systems and developer tools. Some tend to see tools as either/or instead of with/and, Let’s examine the developer tools Terraform and Ansible.
Ansible: Configuration Management and Application Deployment
Ansible is an open-source automation engine that simplifies configuration management, application deployment, and task automation. It uses an agentless architecture, communicating with target systems over SSH.
Ansible uses a procedural approach, which means items are executed from top to bottom because of that it is mostly used for larger deployments.
Engineers and developers create playbooks to configure devices used for the network. The playbook is written in YAML. Inside the playbook, you set tasks that are used to configure designated devices.
Ansible is a wonderful tool if you want more control over your devices and fast configuration of multiple devices. It fits in well with traditional automation frameworks.
Terraform is an open-source infrastructure as code (IaC) tool that enables you to define and provision infrastructure resources across various cloud providers and on-premises environments.
Focus:
Provisioning and managing infrastructure resources (virtual machines, networks, databases, etc.).
Defining the desired state of infrastructure and automating its creation and modification.
Managing infrastructure across multiple cloud providers.
Key Characteristics:
Infrastructure as Code (IaC): Uses HashiCorp Configuration Language (HCL) to define infrastructure.
State Management: Maintains a state file to track infrastructure resources.
Declarative: Focuses on the desired end state, not the steps to achieve it.
Multi-Cloud: Supports various cloud providers (AWS, Azure, Google Cloud) and on-premises environments.
Excellent at building the base infrastructure.
Use Cases:
Provisioning cloud infrastructure.
Managing infrastructure across multiple cloud providers.
Creating and managing software-defined networks.
Creating repeatable infrastructure.
Key Differences and Synergies:
Both tools can be used in Docker workflows. Terraform can provision the infrastructure for Docker hosts, and Ansible can manage Docker containers and applications.
Provisioning vs. Configuration:
Terraform: Provisions infrastructure.
Ansible: Configures systems and deploys applications.
State Management:
Terraform: Relies on state management to track infrastructure.
Ansible: Primarily focuses on the current state of systems during task execution.
Language:
Terraform: Uses HCL (declarative).
Ansible: Uses YAML (procedural/declarative).
Working Together:
A common pattern is to use Terraform to provision infrastructure and then use Ansible to configure the provisioned systems. For example, Terraform creates virtual machines, and Ansible installs and configures software on those machines.
Terraform builds the foundation, and Ansible builds the house on the foundation.
Kubernetes and Docker:
Terraform is well-suited for provisioning the underlying infrastructure for Kubernetes clusters. While Ansible can configure applications running within Kubernetes, Terraform is better at creating the cluster itself.
Most companies are using these two open-source tools together. Common industry practice is to use Terraform to create infrastructure and then Ansible to configure the infrastructure or device. If the containerized solution is used to provision software within the cloud, then Terraform is preferable. On the other hand, if you want to gain reasonable control of your devices and find other ways to deploy underlying services, Ansible is more suitable. These tools will provide more comprehensive solutions in the future.
As companies continue their progress toward using Kubernetes and Docker; they won’t need Ansible to configure the software. If you’re deciding between either other it may be best to have general knowledge of both and continue going deeper into Terraform. I believe Terraform and Kubernetes will be widely used tools moving forward.