Terraform + Ansible: The DevOps Workflow That Actually Works
Read full transcript 14 segments
-
If you have been following my videos, If you have been following my videos, you probably know that I love DevOps you probably know that I love DevOps you probably know that I love DevOps tools, especially infrastructure as code tools, especially infrastructure as code tools, especially infrastructure as code and I regularly use Terraform or these and I regularly use Terraform or these and I regularly use Terraform or these days open tofu and anible throughout all days open tofu and anible throughout all days open tofu and anible throughout all of my home lab projects because I of my home lab projects because I of my home lab projects because I genuinely believe both tools are genuinely believe both tools are genuinely believe both tools are absolutely incredible. They help you absolutely incredible. They help you absolutely incredible. They help you automate infrastructure and provision or automate infrastructure and provision or automate infrastructure and provision or configure systems across all your IT configure systems across all your IT configure systems across all your IT environments so that you do not have to environments so that you do not have to environments so that you do not have to log into an admin interface and do all log into an admin interface and do all log into an admin interface and do all of this by hand. You just describe in of this by hand. You just describe in of this by hand. You just describe in code what you want and the tools takes code what you want and the tools takes code what you want and the tools takes care of making all the necessary changes care of making all the necessary changes care of making all the necessary changes for you. But I know there's also a lot for you. But I know there's also a lot for you. But I know there's also a lot of confusion around what Ansible and of confusion around what Ansible and of confusion around what Ansible and Terraform are actually good at and when Terraform are actually good at and when Terraform are actually good at and when should you use which one? Because many should you use which one? Because many should you use which one? Because many people fall into this trap of comparing people fall into this trap of comparing people fall into this trap of comparing them directly side by side and always them directly side by side and always them directly side by side and always asking hey which tool should I choose asking hey which tool should I choose asking hey which tool should I choose Anible or Terraform and which one is the Anible or Terraform and which one is the Anible or Terraform and which one is the better tool. But here's the thing like better tool. But here's the thing like better tool. But here's the thing like with many tools in IT this is not an with many tools in IT this is not an with many tools in IT this is not an eitheror decision. Terraform and Ansible eitheror decision. Terraform and Ansible eitheror decision. Terraform and Ansible both have their strengths and there are both have their strengths and there are both have their strengths and there are different ways and workflows of managing different ways and workflows of managing different ways and workflows of managing infrastructure and I think instead of infrastructure and I think instead of infrastructure and I think instead of comparing them like competitors, it comparing them like competitors, it comparing them like competitors, it makes a lot more sense to understand how makes a lot more sense to understand how makes a lot more sense to understand how to use them both together because in to use them both together because in to use them both together because in many environments and workflows they many environments and workflows they many environments and workflows they complement each other pretty well. So in complement each other pretty well. So in complement each other pretty well. So in this video I'd like to show you exactly this video I'd like to show you exactly this video I'd like to show you exactly how I'm doing this. We'll take a closer how I'm doing this. We'll take a closer how I'm doing this. We'll take a closer look at my homelap workflows and when look at my homelap workflows and when look at my homelap workflows and when I'm using Terraform/opentofo I'm using Terraform/opentofo I'm using Terraform/opentofo or anible and where their or anible and where their or anible and where their responsibilities sometimes overlap, but responsibilities sometimes overlap, but responsibilities sometimes overlap, but also where it makes a little more sense also where it makes a little more sense also where it makes a little more sense to use the one tool over the other.
-
to use the one tool over the other. to use the one tool over the other. Before we do that though, I also quickly Before we do that though, I also quickly Before we do that though, I also quickly want to talk about secure remote access want to talk about secure remote access want to talk about secure remote access because even when you automate your because even when you automate your because even when you automate your infrastructure, you always need a safe infrastructure, you always need a safe infrastructure, you always need a safe way to reach your servers, SSH way to reach your servers, SSH way to reach your servers, SSH endpoints, and internal admin tools endpoints, and internal admin tools endpoints, and internal admin tools without exposing them directly to the without exposing them directly to the without exposing them directly to the public internet. And for that, my first public internet. And for that, my first public internet. And for that, my first choice is Twin Gate, the sponsor of choice is Twin Gate, the sponsor of choice is Twin Gate, the sponsor of today's video. Two is what we call ZTNA today's video. Two is what we call ZTNA today's video. Two is what we call ZTNA in tech, a zero trust network access in tech, a zero trust network access in tech, a zero trust network access platform that creates secure connections platform that creates secure connections platform that creates secure connections between all of your devices and private between all of your devices and private between all of your devices and private resources. Every request needs to be resources. Every request needs to be resources. Every request needs to be verified and authorized before it goes verified and authorized before it goes verified and authorized before it goes through. And this even works through nut through. And this even works through nut through. And this even works through nut devices and firewalls without any port devices and firewalls without any port devices and firewalls without any port for warnings or firewall exceptions. So for warnings or firewall exceptions. So for warnings or firewall exceptions. So I can securely access all of my HomeLab I can securely access all of my HomeLab I can securely access all of my HomeLab systems no matter where I am. And Twing systems no matter where I am. And Twing systems no matter where I am. And Twing is especially interesting for DevOps is especially interesting for DevOps is especially interesting for DevOps workflows because it provides automation workflows because it provides automation workflows because it provides automation options and integrations for options and integrations for options and integrations for infrastructure as code tools such as infrastructure as code tools such as infrastructure as code tools such as Terraform. And this allows you to manage Terraform. And this allows you to manage Terraform. And this allows you to manage all your Twin Gate resources and access all your Twin Gate resources and access all your Twin Gate resources and access policies as part of your automated policies as part of your automated policies as part of your automated infrastructure workflow instead of infrastructure workflow instead of infrastructure workflow instead of configuring everything manually. So configuring everything manually. So configuring everything manually. So definitely try this out. Check out my definitely try this out. Check out my definitely try this out. Check out my tutorials on how to use and install tutorials on how to use and install tutorials on how to use and install Twing and integrate this into your Twing and integrate this into your Twing and integrate this into your Docker, Kubernetes or Terraform Docker, Kubernetes or Terraform Docker, Kubernetes or Terraform workflows. and the best. Twingate is workflows. and the best. Twingate is workflows. and the best. Twingate is free for up to five users and 10 free for up to five users and 10 free for up to five users and 10 different remote networks. Of course, different remote networks. Of course, different remote networks. Of course, you will find a link to twingate in the you will find a link to twingate in the you will find a link to twingate in the description box down below.
-
description box down below. description box down below. Okay guys, so before we jump into some Okay guys, so before we jump into some Okay guys, so before we jump into some specific examples how you can use specific examples how you can use specific examples how you can use Ansible and Terraform both together, I Ansible and Terraform both together, I Ansible and Terraform both together, I first of all want to get everybody on first of all want to get everybody on first of all want to get everybody on the same page and go a bit deeper into the same page and go a bit deeper into the same page and go a bit deeper into how those tools actually work under the how those tools actually work under the how those tools actually work under the hood and then it will make much more hood and then it will make much more hood and then it will make much more sense in which situation the one tool is sense in which situation the one tool is sense in which situation the one tool is better than the other. Let's first of better than the other. Let's first of better than the other. Let's first of all start with Ansible. The magic of all start with Ansible. The magic of all start with Ansible. The magic of Ansible all happens on one control node Ansible all happens on one control node Ansible all happens on one control node which can be an automation server. It which can be an automation server. It which can be an automation server. It could be a CCD runner or simply your could be a CCD runner or simply your could be a CCD runner or simply your workstation where you execute your workstation where you execute your workstation where you execute your Anible commands. On this control node we Anible commands. On this control node we Anible commands. On this control node we have three components. So first is the have three components. So first is the have three components. So first is the inventory. This tells Anible which inventory. This tells Anible which inventory. This tells Anible which systems you want to manage like server systems you want to manage like server systems you want to manage like server one, server two and so on how they are one, server two and so on how they are one, server two and so on how they are grouped and how anible connects to them. grouped and how anible connects to them. grouped and how anible connects to them. Then we have playbooks. So playbooks are Then we have playbooks. So playbooks are Then we have playbooks. So playbooks are basically just simple YAML files where basically just simple YAML files where basically just simple YAML files where you describe which tasks anible should you describe which tasks anible should you describe which tasks anible should execute. For example, installing execute. For example, installing execute. For example, installing packages, creating users, copying packages, creating users, copying packages, creating users, copying configuration files, or starting and configuration files, or starting and configuration files, or starting and stopping services. It's important to stopping services. It's important to stopping services. It's important to know that playbooks are not limited to know that playbooks are not limited to know that playbooks are not limited to persistent system configurations. So you persistent system configurations. So you persistent system configurations. So you can use them also to execute operational can use them also to execute operational can use them also to execute operational tasks. You are very very flexible with tasks. You are very very flexible with tasks. You are very very flexible with what you can do with it. And when you what you can do with it. And when you what you can do with it. And when you run such a playbook, the Ansible engine run such a playbook, the Ansible engine run such a playbook, the Ansible engine will process this information. It will process this information. It will process this information. It connects to all of the selected systems connects to all of the selected systems connects to all of the selected systems usually through SSH. So you do not need usually through SSH. So you do not need usually through SSH. So you do not need to install a permanent anible agent on to install a permanent anible agent on to install a permanent anible agent on every Linux server before you can manage every Linux server before you can manage every Linux server before you can manage it. Which is a huge advantage over other it. Which is a huge advantage over other it. Which is a huge advantage over other agent-based automation tools. And this agent-based automation tools. And this agent-based automation tools. And this is also the reason why many tech is also the reason why many tech is also the reason why many tech professionals choose Ansible because
-
professionals choose Ansible because professionals choose Ansible because just imagine you need to manage hundreds just imagine you need to manage hundreds just imagine you need to manage hundreds of servers or newly installed systems or of servers or newly installed systems or of servers or newly installed systems or also devices like switches, routers, also devices like switches, routers, also devices like switches, routers, firewalls where you sometimes cannot firewalls where you sometimes cannot firewalls where you sometimes cannot install any additional agent at all. install any additional agent at all. install any additional agent at all. then it is so much easier to just run an then it is so much easier to just run an then it is so much easier to just run an anible playbook that just connects over anible playbook that just connects over anible playbook that just connects over SSH and doesn't need any pre-installed SSH and doesn't need any pre-installed SSH and doesn't need any pre-installed agent. It is also important to agent. It is also important to agent. It is also important to understand that anible just executes all understand that anible just executes all understand that anible just executes all of these tasks in a row that you define of these tasks in a row that you define of these tasks in a row that you define first. So it doesn't need to maintain a first. So it doesn't need to maintain a first. So it doesn't need to maintain a persistent state file like Terraform. persistent state file like Terraform. persistent state file like Terraform. All the desired configuration lives in All the desired configuration lives in All the desired configuration lives in the playbooks. While the current the playbooks. While the current the playbooks. While the current situation or the current state of the situation or the current state of the situation or the current state of the system is inspected on the target system is inspected on the target system is inspected on the target devices whenever the playbook runs or devices whenever the playbook runs or devices whenever the playbook runs or when this specific task is executed and when this specific task is executed and when this specific task is executed and Ansible only makes a change when it's Ansible only makes a change when it's Ansible only makes a change when it's necessary, but it does not really necessary, but it does not really necessary, but it does not really remember what it has done on a previous remember what it has done on a previous remember what it has done on a previous playbook execution, which is sometimes playbook execution, which is sometimes playbook execution, which is sometimes good for flexibility, especially when good for flexibility, especially when good for flexibility, especially when you're making changes to your servers you're making changes to your servers you're making changes to your servers outside of the Ansible playbook. Now outside of the Ansible playbook. Now outside of the Ansible playbook. Now this is very different from Terraform.
-
this is very different from Terraform. this is very different from Terraform. First step, you write the configuration First step, you write the configuration First step, you write the configuration file similar to an anible playbook, but file similar to an anible playbook, but file similar to an anible playbook, but it of course uses a different syntax. it of course uses a different syntax. it of course uses a different syntax. And instead of defining commands or And instead of defining commands or And instead of defining commands or tasks that you need to execute, you just tasks that you need to execute, you just tasks that you need to execute, you just define resources such as virtual define resources such as virtual define resources such as virtual machines, networks, DNS records, cloud machines, networks, DNS records, cloud machines, networks, DNS records, cloud services or even resources inside a SAS services or even resources inside a SAS services or even resources inside a SAS platform. And then Terraform or open platform. And then Terraform or open platform. And then Terraform or open tofu use providers that communicate with tofu use providers that communicate with tofu use providers that communicate with those platforms where you need to create those platforms where you need to create those platforms where you need to create these resources. For example, a Proxmox these resources. For example, a Proxmox these resources. For example, a Proxmox provider translates all the resource provider translates all the resource provider translates all the resource definitions into API requests that the definitions into API requests that the definitions into API requests that the Proxmox server understands. Once a Proxmox server understands. Once a Proxmox server understands. Once a configuration is written, you can also configuration is written, you can also configuration is written, you can also create a plan to evaluate the current create a plan to evaluate the current create a plan to evaluate the current situation on the devices and it builds a situation on the devices and it builds a situation on the devices and it builds a dependency graphs and calculates which dependency graphs and calculates which dependency graphs and calculates which resources it needs to create, change, resources it needs to create, change, resources it needs to create, change, replace or destroy. And that is an replace or destroy. And that is an replace or destroy. And that is an important difference to Ansible because important difference to Ansible because important difference to Ansible because this can happen even before the actual this can happen even before the actual this can happen even before the actual execution. so that you can review those execution. so that you can review those execution. so that you can review those proposed actions before anything proposed actions before anything proposed actions before anything happens. Of course, Ansible also has a happens. Of course, Ansible also has a happens. Of course, Ansible also has a similar check mode that can preview many similar check mode that can preview many similar check mode that can preview many changes, but the support depends on the changes, but the support depends on the changes, but the support depends on the individual modules and it is not as good individual modules and it is not as good individual modules and it is not as good as Terraform or open to. Now, when you as Terraform or open to. Now, when you as Terraform or open to. Now, when you apply the changes, it will also do apply the changes, it will also do apply the changes, it will also do something else. It will keep track of something else. It will keep track of something else. It will keep track of the current state. So that means that it the current state. So that means that it the current state. So that means that it maps the resources from your maps the resources from your maps the resources from your configuration file to the resources on configuration file to the resources on configuration file to the resources on the actual infrastructure storing it in the actual infrastructure storing it in the actual infrastructure storing it in a state file that allows Terraform or a state file that allows Terraform or a state file that allows Terraform or open TOFU to manage the entire life
-
open TOFU to manage the entire life open TOFU to manage the entire life cycle instead of just running a list of cycle instead of just running a list of cycle instead of just running a list of commands. This life cycle model is one commands. This life cycle model is one commands. This life cycle model is one of the Terraforms or Open TOFU's biggest of the Terraforms or Open TOFU's biggest of the Terraforms or Open TOFU's biggest strengths. But it also defines where the strengths. But it also defines where the strengths. But it also defines where the tool is less useful. like a terraform tool is less useful. like a terraform tool is less useful. like a terraform normally performs an action because the normally performs an action because the normally performs an action because the desired state of a managed resource has desired state of a managed resource has desired state of a managed resource has changed. So that means changing a name changed. So that means changing a name changed. So that means changing a name of an object or changing a value like of an object or changing a value like of an object or changing a value like the number of CPU cores on a virtual the number of CPU cores on a virtual the number of CPU cores on a virtual machine. It is not really designed as a machine. It is not really designed as a machine. It is not really designed as a general purpose job runner for general purpose job runner for general purpose job runner for operational tasks like if you want to operational tasks like if you want to operational tasks like if you want to restart a service or shut down restart a service or shut down restart a service or shut down something, right? This is what you can something, right? This is what you can something, right? This is what you can better do with Ansible. And also if you better do with Ansible. And also if you better do with Ansible. And also if you do any changes outside of Terraform, you do any changes outside of Terraform, you do any changes outside of Terraform, you can run into problems too. Sometimes the can run into problems too. Sometimes the can run into problems too. Sometimes the provider does refresh some resources and provider does refresh some resources and provider does refresh some resources and it can detect changes made outside of it can detect changes made outside of it can detect changes made outside of Terraform. But this is not always the Terraform. But this is not always the Terraform. But this is not always the case and it really depends on the case and it really depends on the case and it really depends on the provider's implementation. So in provider's implementation. So in provider's implementation. So in terapform or open tufo that state file terapform or open tufo that state file terapform or open tufo that state file is very important and it also becomes is very important and it also becomes is very important and it also becomes challenging like when you work from challenging like when you work from challenging like when you work from multiple computers or you work together multiple computers or you work together multiple computers or you work together with a team because then everyone or with a team because then everyone or with a team because then everyone or every device needs access to the same every device needs access to the same every device needs access to the same state file. That's why in larger state file. That's why in larger state file. That's why in larger projects you normally store this in a projects you normally store this in a projects you normally store this in a central remote backend instead of central remote backend instead of central remote backend instead of keeping them separate on every device.
-
keeping them separate on every device. keeping them separate on every device. That is also why most people use Ansible That is also why most people use Ansible That is also why most people use Ansible mainly for installing things, changing mainly for installing things, changing mainly for installing things, changing system configurations or running on system configurations or running on system configurations or running on demand automations and terraform and demand automations and terraform and demand automations and terraform and open tofu mainly where you need to keep open tofu mainly where you need to keep open tofu mainly where you need to keep track of all the resources you have track of all the resources you have track of all the resources you have created through an entire life cycle and created through an entire life cycle and created through an entire life cycle and use a central storage location for the use a central storage location for the use a central storage location for the back end. But this boundary is not back end. But this boundary is not back end. But this boundary is not absolute. Of course, you can use Ansible absolute. Of course, you can use Ansible absolute. Of course, you can use Ansible to also create infrastructure resources to also create infrastructure resources to also create infrastructure resources and Terraform can also execute and Terraform can also execute and Terraform can also execute configuration steps. A good example is configuration steps. A good example is configuration steps. A good example is Proxmox with the Proxmox provider on Proxmox with the Proxmox provider on Proxmox with the Proxmox provider on open tofu or there's a similar module open tofu or there's a similar module open tofu or there's a similar module for Terraform as well. You can define a for Terraform as well. You can define a for Terraform as well. You can define a virtual machine as a resource and you virtual machine as a resource and you virtual machine as a resource and you can use Terraform or open TOFU to create can use Terraform or open TOFU to create can use Terraform or open TOFU to create this machine to manage its life cycle this machine to manage its life cycle this machine to manage its life cycle change configuration settings. But of change configuration settings. But of change configuration settings. But of course, Ansible can also do kind of the course, Ansible can also do kind of the course, Ansible can also do kind of the same thing like there is a community same thing like there is a community same thing like there is a community project or a community collection anible project or a community collection anible project or a community collection anible that can also do things like creating that can also do things like creating that can also do things like creating resources on Proxmox like virtual resources on Proxmox like virtual resources on Proxmox like virtual machines, alexe containers, provision machines, alexe containers, provision machines, alexe containers, provision it, changing configurations and so on.
-
it, changing configurations and so on. it, changing configurations and so on. And this is exactly where people get And this is exactly where people get And this is exactly where people get confused. So should I use anible or open confused. So should I use anible or open confused. So should I use anible or open tofu to create and manage my virtual tofu to create and manage my virtual tofu to create and manage my virtual machines? And I think it really helps to machines? And I think it really helps to machines? And I think it really helps to stop looking at the individual features, stop looking at the individual features, stop looking at the individual features, providers and what you can do with this providers and what you can do with this providers and what you can do with this or another tool and instead look at the or another tool and instead look at the or another tool and instead look at the complete life cycle of an infrastructure complete life cycle of an infrastructure complete life cycle of an infrastructure which normally starts with defining which normally starts with defining which normally starts with defining something, creating it, bootstrapping, something, creating it, bootstrapping, something, creating it, bootstrapping, configuration, operating, replacement, configuration, operating, replacement, configuration, operating, replacement, and destroy. Although I have to admit and destroy. Although I have to admit and destroy. Although I have to admit this is of course not always the full this is of course not always the full this is of course not always the full picture of what you need to do in an IT picture of what you need to do in an IT picture of what you need to do in an IT environment. But I think mapping these environment. But I think mapping these environment. But I think mapping these tools and their strengths on such a tools and their strengths on such a tools and their strengths on such a chart helps to understand better in what chart helps to understand better in what chart helps to understand better in what situations the one tool has an advantage situations the one tool has an advantage situations the one tool has an advantage over the other. So even if technically over the other. So even if technically over the other. So even if technically both tools can do many of the same both tools can do many of the same both tools can do many of the same things. So you can see they have overlap things. So you can see they have overlap things. So you can see they have overlap here and there they certainly have their here and there they certainly have their here and there they certainly have their strengths. And let's make this practical strengths. And let's make this practical strengths. And let's make this practical with showing you my home lab environment with showing you my home lab environment with showing you my home lab environment in my Proxbox automation project. Open in my Proxbox automation project. Open in my Proxbox automation project. Open TOFU or Terraform mostly owns the life TOFU or Terraform mostly owns the life TOFU or Terraform mostly owns the life cycle of resources. If I want to cycle of resources. If I want to cycle of resources. If I want to provision like two, three or four more provision like two, three or four more provision like two, three or four more virtual machines for testing. I can virtual machines for testing. I can virtual machines for testing. I can simply just copy one of these Terraform simply just copy one of these Terraform simply just copy one of these Terraform files. I can make adjustments to the files. I can make adjustments to the files. I can make adjustments to the specific places where I need changes specific places where I need changes specific places where I need changes like with memory, CPU mostly or um disk like with memory, CPU mostly or um disk like with memory, CPU mostly or um disk capacity, IP addresses. Everything is capacity, IP addresses. Everything is capacity, IP addresses. Everything is defined in here. And I also have defined defined in here. And I also have defined defined in here. And I also have defined DNS records. Like if I create a new DNS records. Like if I create a new DNS records. Like if I create a new virtual machine that has a static IP
-
virtual machine that has a static IP virtual machine that has a static IP address, I mostly also want to create a address, I mostly also want to create a address, I mostly also want to create a DNS record that resolves that IP address DNS record that resolves that IP address DNS record that resolves that IP address using a memorable name. And I'm also using a memorable name. And I'm also using a memorable name. And I'm also using that to create dependent resources using that to create dependent resources using that to create dependent resources like uh netbox documentation. Um, so I'm like uh netbox documentation. Um, so I'm like uh netbox documentation. Um, so I'm also documenting or adding the IP also documenting or adding the IP also documenting or adding the IP address and the VM as another resource address and the VM as another resource address and the VM as another resource on my IPAM inventory management system. on my IPAM inventory management system. on my IPAM inventory management system. Here I'm also adding the Kubernetes Here I'm also adding the Kubernetes Here I'm also adding the Kubernetes stuffs on three virtual machines. So stuffs on three virtual machines. So stuffs on three virtual machines. So therefore I have also created resources therefore I have also created resources therefore I have also created resources via Terraform that document the IP via Terraform that document the IP via Terraform that document the IP address of that cluster of the load address of that cluster of the load address of that cluster of the load balancer and of course the Proxmox balancer and of course the Proxmox balancer and of course the Proxmox cluster itself. So there's a lot going cluster itself. So there's a lot going cluster itself. So there's a lot going on here and that I'm mostly using for on here and that I'm mostly using for on here and that I'm mostly using for managing resources. The cool thing what managing resources. The cool thing what managing resources. The cool thing what open tofu does and where I think this open tofu does and where I think this open tofu does and where I think this becomes really practical for managing becomes really practical for managing becomes really practical for managing resources is that you can add references resources is that you can add references resources is that you can add references to objects of other resources. For to objects of other resources. For to objects of other resources. For example, when we jump here into this example, when we jump here into this example, when we jump here into this file, you can see that I defined a file, you can see that I defined a file, you can see that I defined a static IP address for that virtual static IP address for that virtual static IP address for that virtual machine. If I want to document this in machine. If I want to document this in machine. If I want to document this in my IPAM system, I don't need to repeat my IPAM system, I don't need to repeat my IPAM system, I don't need to repeat that IP address. I just referenced that that IP address. I just referenced that that IP address. I just referenced that specific object in another value. So uh specific object in another value. So uh specific object in another value. So uh here for example it's a DNS record and here for example it's a DNS record and here for example it's a DNS record and for the address I have created a for the address I have created a for the address I have created a function that it basically extracts that function that it basically extracts that function that it basically extracts that IP address as a value and puts that IP address as a value and puts that IP address as a value and puts that automatically here into this DNS record automatically here into this DNS record automatically here into this DNS record and Terraform or open TUFO is and Terraform or open TUFO is and Terraform or open TUFO is intelligent enough that it automatically intelligent enough that it automatically intelligent enough that it automatically creates a plan of what resources it
-
creates a plan of what resources it creates a plan of what resources it needs to create before the others and needs to create before the others and needs to create before the others and this is why I mostly prefer using this is why I mostly prefer using this is why I mostly prefer using Terraform for these type of tasks. Let Terraform for these type of tasks. Let Terraform for these type of tasks. Let me give you a quick example how easy me give you a quick example how easy me give you a quick example how easy this is for me. So when I jump into this this is for me. So when I jump into this this is for me. So when I jump into this repository because I have defined repository because I have defined repository because I have defined everything in code, I can just tell my everything in code, I can just tell my everything in code, I can just tell my AI agent, hey please create three new AI agent, hey please create three new AI agent, hey please create three new test VMs just like my pro VMs but with test VMs just like my pro VMs but with test VMs just like my pro VMs but with IP addresses from the range 1023x IP addresses from the range 1023x IP addresses from the range 1023x create free DNS records for these create free DNS records for these create free DNS records for these servers as well defined as open tofu servers as well defined as open tofu servers as well defined as open tofu resources. Then the AI agent will gather resources. Then the AI agent will gather resources. Then the AI agent will gather the information from the existing the information from the existing the information from the existing Terraform resource files and it will Terraform resource files and it will Terraform resource files and it will start creating new files that look start creating new files that look start creating new files that look similar to the others with all the similar to the others with all the similar to the others with all the resource definition for these virtual resource definition for these virtual resource definition for these virtual machines. And it also automatically has machines. And it also automatically has machines. And it also automatically has added the DNS records and the entries added the DNS records and the entries added the DNS records and the entries for the test VMs. So it starts preparing for the test VMs. So it starts preparing for the test VMs. So it starts preparing the plan apply command without approval. the plan apply command without approval. the plan apply command without approval. So now you can see that open TUFO in the So now you can see that open TUFO in the So now you can see that open TUFO in the background is already creating these background is already creating these background is already creating these virtual machines. If we log into my virtual machines. If we log into my virtual machines. If we log into my Proxmox cluster, we should also be able Proxmox cluster, we should also be able Proxmox cluster, we should also be able to see these VMs that are currently to see these VMs that are currently to see these VMs that are currently created. All right, server test 7 is created. All right, server test 7 is created. All right, server test 7 is already there. Server test 8 has been already there. Server test 8 has been already there. Server test 8 has been created on the third Proxmox node and created on the third Proxmox node and created on the third Proxmox node and server test 6 is currently being created server test 6 is currently being created server test 6 is currently being created here on the first one. So everything has here on the first one. So everything has here on the first one. So everything has been completed. So now I have my been completed. So now I have my been completed. So now I have my resources and I can also very easily resources and I can also very easily resources and I can also very easily manage everything. If I need to change a manage everything. If I need to change a manage everything. If I need to change a value like adding more CPU cores or less
-
value like adding more CPU cores or less value like adding more CPU cores or less memory whatever I can make changes here memory whatever I can make changes here memory whatever I can make changes here let the open tofu command manage that let the open tofu command manage that let the open tofu command manage that and make the necessary changes for me. and make the necessary changes for me. and make the necessary changes for me. This is also why saying Terraform is This is also why saying Terraform is This is also why saying Terraform is only good for infrastructure management only good for infrastructure management only good for infrastructure management like creating the VMs and Ansible is like creating the VMs and Ansible is like creating the VMs and Ansible is only there for configuration would be only there for configuration would be only there for configuration would be too simple because DNS records or netbox too simple because DNS records or netbox too simple because DNS records or netbox entries could be considered entries could be considered entries could be considered configuration but because they still configuration but because they still configuration but because they still belong to the same life cycle as the belong to the same life cycle as the belong to the same life cycle as the virtual machine I want to manage. I'm virtual machine I want to manage. I'm virtual machine I want to manage. I'm using terraform for applying these using terraform for applying these using terraform for applying these configuration settings as well because configuration settings as well because configuration settings as well because always when these objects are declared always when these objects are declared always when these objects are declared together open tofu can show me the together open tofu can show me the together open tofu can show me the complete change in one place and when I complete change in one place and when I complete change in one place and when I change information like the IP address change information like the IP address change information like the IP address here that also changes all the other here that also changes all the other here that also changes all the other values like the DNS record and the values like the DNS record and the values like the DNS record and the documentation system but I still use documentation system but I still use documentation system but I still use anible for other things like after open anible for other things like after open anible for other things like after open has created these virtual machines the has created these virtual machines the has created these virtual machines the virtual machine still needs it operating virtual machine still needs it operating virtual machine still needs it operating system configuration. So standard system configuration. So standard system configuration. So standard packages I need to install like for packages I need to install like for packages I need to install like for example the Prometheus node exporter or example the Prometheus node exporter or example the Prometheus node exporter or the QMO guest agent that I want to the QMO guest agent that I want to the QMO guest agent that I want to install on these test machines with install on these test machines with install on these test machines with Ansible. So what I can do now is saying Ansible. So what I can do now is saying Ansible. So what I can do now is saying like can you install the core packages like can you install the core packages like can you install the core packages like node exporter guest agent on all like node exporter guest agent on all like node exporter guest agent on all three test machines via anible that will three test machines via anible that will three test machines via anible that will modify the playbooks that I've already modify the playbooks that I've already modify the playbooks that I've already created for this repository. So here
-
created for this repository. So here created for this repository. So here I've added an anible baseline role. So I've added an anible baseline role. So I've added an anible baseline role. So that contains some of the default values that contains some of the default values that contains some of the default values like for every Linux server I usually like for every Linux server I usually like for every Linux server I usually want to install NFS command the want to install NFS command the want to install NFS command the prometheus node exporter unzip and for prometheus node exporter unzip and for prometheus node exporter unzip and for the virtual machines I always want to the virtual machines I always want to the virtual machines I always want to install the QMO guest agent. So here for install the QMO guest agent. So here for install the QMO guest agent. So here for example you can see that the agent example you can see that the agent example you can see that the agent already added the free test servers to already added the free test servers to already added the free test servers to the anible playbook and now executes the anible playbook and now executes the anible playbook and now executes anible in the background to install and anible in the background to install and anible in the background to install and provision the packages on these virtual provision the packages on these virtual provision the packages on these virtual Linux server. And of course Ansible only Linux server. And of course Ansible only Linux server. And of course Ansible only installs something when this is missing installs something when this is missing installs something when this is missing on the virtual machine. So for example on the virtual machine. So for example on the virtual machine. So for example the QM guest agent I've also included in the QM guest agent I've also included in the QM guest agent I've also included in the Proxmox template. So technically I the Proxmox template. So technically I the Proxmox template. So technically I do not need to run this step but Ansible do not need to run this step but Ansible do not need to run this step but Ansible will automatically check hey is this will automatically check hey is this will automatically check hey is this missing or is this installed. So missing or is this installed. So missing or is this installed. So therefore anible is much much better for therefore anible is much much better for therefore anible is much much better for these type of installation or these type of installation or these type of installation or configuration settings where the configuration settings where the configuration settings where the playbook doesn't really care whether a playbook doesn't really care whether a playbook doesn't really care whether a machine was created 5 minutes ago or machine was created 5 minutes ago or machine was created 5 minutes ago or when this is already running for years. when this is already running for years. when this is already running for years. It just connects to the current system It just connects to the current system It just connects to the current system does all the installation and changing does all the installation and changing does all the installation and changing steps that you have configured. So to steps that you have configured. So to steps that you have configured. So to summarize this for me open to is there summarize this for me open to is there summarize this for me open to is there whenever I need to create or manage whenever I need to create or manage whenever I need to create or manage virtual machines uh changing certain virtual machines uh changing certain virtual machines uh changing certain values like CPU, disk, network or other values like CPU, disk, network or other values like CPU, disk, network or other dependent resources like DNS entries, dependent resources like DNS entries, dependent resources like DNS entries, netbox configuration and so on and takes netbox configuration and so on and takes netbox configuration and so on and takes over when the machine is actually over when the machine is actually over when the machine is actually provisioned and running and then it provisioned and running and then it provisioned and running and then it manages things on the operating systems, manages things on the operating systems, manages things on the operating systems, packages to be installed, applications
-
packages to be installed, applications packages to be installed, applications running inside and it executes running inside and it executes running inside and it executes operational workflows like restarting. operational workflows like restarting. operational workflows like restarting. services, stopping services, when I need services, stopping services, when I need services, stopping services, when I need to update things, and so on. When I'm to update things, and so on. When I'm to update things, and so on. When I'm done with all of the testing, if I've done with all of the testing, if I've done with all of the testing, if I've tested everything, if everything is tested everything, if everything is tested everything, if everything is correct, I can simply just uh say uh correct, I can simply just uh say uh correct, I can simply just uh say uh delete the open tofu files to destroy delete the open tofu files to destroy delete the open tofu files to destroy the VMs, then the agent will simply just the VMs, then the agent will simply just the VMs, then the agent will simply just delete these three files. And when I run delete these three files. And when I run delete these three files. And when I run Terraform again, it will know that the Terraform again, it will know that the Terraform again, it will know that the resources have been created previously. resources have been created previously. resources have been created previously. So, it needs to delete these resources So, it needs to delete these resources So, it needs to delete these resources on the actual systems. And again this on the actual systems. And again this on the actual systems. And again this does not only include the virtual does not only include the virtual does not only include the virtual machine on proxmox but it also includes machine on proxmox but it also includes machine on proxmox but it also includes the DNS records and the documentation on the DNS records and the documentation on the DNS records and the documentation on netbox. So everything that depends on netbox. So everything that depends on netbox. So everything that depends on the life cycle of the VM and what the life cycle of the VM and what the life cycle of the VM and what Ensible has done inside does not really Ensible has done inside does not really Ensible has done inside does not really matter anymore and I think this is the matter anymore and I think this is the matter anymore and I think this is the most important takeaway because in my most important takeaway because in my most important takeaway because in my opinion there's no real winner in this opinion there's no real winner in this opinion there's no real winner in this terraform versus anible debate and sure terraform versus anible debate and sure terraform versus anible debate and sure you can use both tools for kind of the you can use both tools for kind of the you can use both tools for kind of the similar things but they approach these similar things but they approach these similar things but they approach these responsibilities in very different ways responsibilities in very different ways responsibilities in very different ways and I always choose the tool which has and I always choose the tool which has and I always choose the tool which has real value for a specific use case. So real value for a specific use case. So real value for a specific use case. So that's exactly how I do this in my home that's exactly how I do this in my home that's exactly how I do this in my home lab. That's why I use both Enzible and lab. That's why I use both Enzible and lab. That's why I use both Enzible and Terraform at the same time for different Terraform at the same time for different Terraform at the same time for different things. And of course, I can just expand things. And of course, I can just expand things. And of course, I can just expand this to application deployment like this to application deployment like this to application deployment like where I'm managing and creating the where I'm managing and creating the where I'm managing and creating the actual virtual machines with Terraform.
-
actual virtual machines with Terraform. actual virtual machines with Terraform. But when I need to install the Docker But when I need to install the Docker But when I need to install the Docker engine or I need to deploy a Docker engine or I need to deploy a Docker engine or I need to deploy a Docker compos file on a remote machine, I compos file on a remote machine, I compos file on a remote machine, I personally would use Ansible for this. personally would use Ansible for this. personally would use Ansible for this. But yeah, that's just what I found out But yeah, that's just what I found out But yeah, that's just what I found out for me to work the best. Now I want to for me to work the best. Now I want to for me to work the best. Now I want to hear from you guys. So are you using hear from you guys. So are you using hear from you guys. So are you using Ansible, Terraform or Open TOFU in your Ansible, Terraform or Open TOFU in your Ansible, Terraform or Open TOFU in your home lab? By the way, you might have home lab? By the way, you might have home lab? By the way, you might have seen how useful AI is when you use seen how useful AI is when you use seen how useful AI is when you use infrastructure as code. Maybe you do infrastructure as code. Maybe you do infrastructure as code. Maybe you do follow the same process or you were follow the same process or you were follow the same process or you were inspired by this. Let's have an open inspired by this. Let's have an open inspired by this. Let's have an open discussion. So please leave me some discussion. So please leave me some discussion. So please leave me some comments or let's continue talking about comments or let's continue talking about comments or let's continue talking about this on my discord server. Link is also this on my discord server. Link is also this on my discord server. Link is also in the description. And as always, thank in the description. And as always, thank in the description. And as always, thank you so much for watching. Thanks to all you so much for watching. Thanks to all you so much for watching. Thanks to all the supporters of my channel. You guys the supporters of my channel. You guys the supporters of my channel. You guys are so amazing. You make all these free are so amazing. You make all these free are so amazing. You make all these free tutorials possible. And of course, I'm tutorials possible. And of course, I'm tutorials possible. And of course, I'm going to catch you in the next one. Take going to catch you in the next one. Take going to catch you in the next one. Take care.
Summary
The main theme is effectively using infrastructure as code tools, specifically Terraform/OpenTofu and Ansible, for automating IT environments. The speaker emphasizes that these tools are complementary, not competitive, and the practical takeaway is to understand how to leverage both together for greater efficiency in managing infrastructure. This is further supported by the need for secure remote access, exemplified by the sponsor TwinGate's ZTNA solution.