Skip to Content

Overview Workflow Architecture of Terraform and Ansible

2/27/2025 by Nanda

Terraform

Terraform is an infrastructure automation tools from HashiCorp, designed to provision and manage life cycle of infrastructure resources in any cloud provider or data centers. It helps to provision, deprovision and manage resources from scratch and also able to do configuration management on created resources but it is not best practice to use for this. I will explain why we shouldn’t use terraform for configuration management in later post. So, we can say that terraform is designed to use for infrastructure provisioning tools.

Ansible

Ansible is an open-source automation tools from RedHat, that automates provisioning, configuration management, application deployment, orchestration, and many other IT processes. It is mainly used for configuration management, application deployment, and task automation and also able to use for provisioning infrastructure but ansible it is not best practice to use for this use cases. So we can say that ansible is designed to use for configuration management tools.

How does Terraform work?

Before explaining how terraform works, I would prefer to show overview workflow architecture diagram : you know “A picture is worth a thousand words”.

  1. To be able to create and manage resources on any provider through application programming interfaces (APIs), you first need to download provider plugins of which cloud provider you want to manage according to your business use cases from this following links.

https://registry.terraform.io/browse/providers

​I will show the sample code of how you can download your required providers. In my use cases, I ​want to provision and manage resources on AWS cloud provider so that I create file name called ​“providers.tf” in local machine.

After that you can download the provider plugins through the following commands:


2. ​After that you can do write workflow in your main.tf file according to your business use cases to define, create and manage resources.
I will show sample code to create ec2 instances on AWS cloud provider in main.tf file.

You can do plan workflow to know an execution plan describing the infrastructure it will create, update, or destroy based on the existing infrastructure and your configuration with the following command.


Finally, after you have review the execution plan above, you can approve it with this following commands to create, update the infrastructure.


This is the brief overview workflow of how you can manage the infrastructure according your use cases through terraform.

How does Ansible work?

Before explaining how ansible works, I would prefer to show overview workflow architecture diagram : you know “A picture is worth a thousand words”.

  1. Ansible is an agentless and doesn’t require to install ansible on managed nodes so that you only need to install ansible packages to do configuration management according to your business use cases on your managed nodes. It makes connections using SSH or other authentication methods to your managed nodes from control nodes. So control nodes and managed nodes must have network connections first. In a nutshell, ansible manage to the control nodes using ansible modules based on the required sometimes you need to install additional modules from this following repository.

Ansible Galaxy( community-based ansible content repository )

Ansible Galaxy 

https://galaxy.ansible.com/ui/collections/

Automation Hub( red-hat official ansible content repository )

Automation Hub

https://console.redhat.com/ansible/automation-hub

Python is mandatory to be installed on both the controlling and the target nodes in most cases for most of the ansible modules are written in python so that without python on control nodes, ansible cannot run the function.

2. After you have installed prerequisites mentioned above, you can start writing ansible playbook according to your use cases.
You first need to write inventory file with your favorite formats INI or YAML. This inventory or host file contains the managed nodes lists of hostname or ip address.
I will show the sample inventory file called “inventory” which is written in INI format.


3.Then define your inventory file location and other required configuration to run the ansible playbook in ansible configuration file called: “ansible.cfg” file.

4.Finally, develop an ansible playbook according your use cases to do the configuration to the managed nodes.
I will show the sample code to create new users on linux servers in “users.yml” file in this example.

After you have developed the playbook, you can run with the following command:


This is the brief overview workflow of how you can manage the infrastructure according your use cases through ansible.

URL test with Prometheus and Grafana
Feb 25, 2025 by Soe Wai Lin