Ansible vs. Terraform

lightsong發表於2024-07-13

How to Use Terraform and Ansible Together: A Practical Example

https://www.cloudbolt.io/terraform-best-practices/terraform-vs-ansible/

Now that you know the differences between Terraform vs. Ansible, let’s walk through a real-world example of how you can use them together to manage infrastructure. In this tutorial, we will:

  1. Create a few EC2 instances in AWS using Terraform
  2. Install NGINX on all of the instances using Ansible

https://www.redhat.com/en/topics/automation/ansible-vs-terraform

Many of our customers use multiple automation solutions at the same time. When they deploy applications in the cloud, for example, they often start provisioning the cloud infrastructure with CloudFormation or Terraform and then perform the ongoing configuration of applications and processes with Ansible Automation Platform.

Orchestration is the coordinated execution of multiple workflows. Each workflow executes one or more tasks. Orchestrated together, these workflows automate the configuration and management of complex systems, applications, and services. This coordination usually follows pre-established rules defined in a policy. Orchestration can also coordinate multiple automation solutions. Those, in turn, execute the automation workflows.

Both Ansible and Terraform can act as orchestrators as they can invoke multiple automation workflows in sequence following specific policies. Ansible has built-in modules to connect to and manage other automation tools (including Terraform). As a result, you can standardize your approach to automation across your entire IT estate, using Ansible as the top-level, common language for all teams.

Provisioning is the process of creating and deploying IT infrastructure for applications and services.

Both Ansible and Terraform can provision (and deprovision) IT infrastructure. Ansible can also provision apps and services.

Configuration management is the process of defining and maintaining the configuration of infrastructure, applications, and services.

Like many other automation solutions, Ansible and Terraform can both define configurations and apply them to various infrastructure targets. However, their approach to configuration management differs. Terraform uses an approach called declarative programming, which tries to preserve the configuration of an IT infrastructure by defining a desired state. Ansible uses a procedural (or imperative) programming approach, which tries to preserve the configuration of an IT infrastructure by defining the steps to reach a desired state. Each process is detailed below.

An Infrastructure as Code (IaC) approach defines and provisions infrastructure through code that will be executed automatically, instead of through manual processes. By treating an IT infrastructure as code, organizations can automate management tasks, benefitting from best practices of software development and reducing human error.

Both Ansible and Terraform are IaC tools, though, as mentioned, the programming used by each solution differs.

相關文章