{
  "id": 5056257,
  "title": "IaC além do Terraform - Ansible para provisionamento e configuração",
  "url": "https://urgent.news/2026/09/02/iac-alem-do-terraform-ansible-para-provisionamento-e-configuracao",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-02T09:30:44.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/apsis-cc/iac-alem-do-terraform-ansible-para-provisionamento-e-configuracao-le9"
  },
  "original_language": "pt",
  "account": "Provisioning and configuration are two distinct stages in the process of setting up infrastructure. Terraform, introduced in a previous article, handles the provisioning aspect by communicating with cloud APIs to create, update, or destroy resources. The mental model for Terraform is declarative and state-driven, focusing on the desired state of a resource such as an instance type, network, or disk. Ansible, on the other hand, is a configuration management tool that connects to machines already present (using SSH without requiring an agent) and executes tasks to bring them into the desired state: installing Nginx, setting up a configuration file, or ensuring a service is running. It's common to see both Terraform and Ansible integrated into the same pipeline, with Terraform creating the infrastructure and Ansible configuring what's within. Provisioning handles the hardware, while configuration takes care of the software.\n\nThe fundamental concepts of Ansible include inventory, playbooks, modules, roles, idempotency, and agentless operation. Inventory is a list of managed machines, grouped logically (e.g., webservers, databases). This list can be static (INI or YAML) or dynamically generated (e.g., from AWS tags). A playbook is a YAML file that outlines the sequence of tasks to be executed on specific groups of inventory machines. Modules are the building blocks of tasks, with ready-to-use modules for a wide range of operations, such as apt, yum, copy, service, user, template, cloud-specific modules, and more. Roles package playbooks, variables, templates, and related files, representing a specific responsibility (e.g., an nginx role that knows how to install and configure Nginx). Ansible's idempotency ensures that running the same playbook multiple times yields the same final result without causing side effects. If a package is already installed, apt will simply do nothing on the second run. Ansible also operates agentlessly, connecting via SSH to managed machines, copying necessary modules, executing tasks, and cleaning up afterwards, which simplifies the initial setup process.\n\nIn practice, inventory plays a crucial role. The `hosts.ini` file in the `inventory/` directory groups machines by their intended role. For instance, the `webservers` group lists servers with their respective IP addresses. Variables can be defined at the group level, such as `ansible_user` and `ansible_ssh_private_key_file`, which specify the credentials for connection and authentication.\n\nA real playbook example demonstrates configuring a web server after provisioning. Assuming the VM was created by Terraform or OpenTofu, this playbook focuses on installing Nginx, creating a deploy user, copying a custom configuration file, and ensuring the firewall allows the correct port. The playbook starts by updating the package cache, installing Nginx, creating a deploy user, copying the Nginx configuration template, enabling the site link, and opening the HTTP port in the firewall. It also includes a handler to reload Nginx whenever a related task notifies it, avoiding unnecessary service restarts. The playbook demonstrates the use of notify/handler mechanisms to streamline the process, ensuring that the Nginx service is only reloaded once, even if multiple tasks trigger it. This integrated approach of Terraform and Ansible showcases how they can work together efficiently within a single pipeline, each handling its designated task – provisioning the hardware and configuring the software.",
  "summary": "1. Provisionar não é configurar No artigo anterior desta série, vimos o OpenTofu como uma alternativa (ou substituto direto) ao Terraform para a tarefa de provisionar infraestrutura — criar VMs, redes, bancos de dados gerenciados, buckets. Mas provisionar um servidor é só o primeiro passo: depois que a VM existe, alguém precisa instalar pacotes, configurar usuários, aplicar hardening, subir a…",
  "key_points": [
    "Terraform handles provisioning by communicating with cloud APIs.",
    "Ansible configures machines after provisioning via SSH.",
    "Terraform and Ansible can be integrated into a single pipeline."
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}