Using Magic Variables for Service Discovery in Ansible - Ansible Tutorial

Опубликовано: 28 Октябрь 2024
на канале: Taryn Leese
95
2

Using Magic Variables for Service Discovery in Ansible is a free tutorial by Gourav Shah from Ansible course
Link to this course(Special Discount):
https://www.udemy.com/course/ultimate...
This is the best Ansible Course
Course summary:
What is ansible, why its needed and how it works
How to configure ansible and setup static/dynamic inventories
Ad hoc server management, running jobs in parallel
Managing systems entities using ansible Modules
Writing Playbooks to define the state of infrastructure as a code
Creating modular, reusable code with Roles
Creating dynmic code with vars and templates
Using Ansible Galaxy
Encrypting sensitive data with Vault
Service Discovery and managing Multiple Environments
Application Deployment Strategies, Rolling Updates
English [Auto]
In the last lesson we enabled the fact gashing in this lesson we're going to start using those facts along with the magic variables and how we do our auto configuration followed balancers using the magic variable so fact gashing configuration is right there. And on the left hand side you see the facts being generated and we're going to use a code such similar to those to create our configuration to discover let's say ansible zero IPV for a dress and that comes from the fact so you can actually go and look at let's say one of the files. And if you go and look at ansible IPV for search for that and us zero and we find out that IPV for address for each zero. And that's what you see there so IPV for addresses that IP address. And that's what we want to fetch that IP address of that host that we want to fetch and add to other load balancer. Similarly we can find any other properties that you would want with the host device itself. The one we looked at in the magic variables. Now where do we add this is inside the template. And for us the you know the role is a proxy the one we have taken from Galaxie So we'll go to the Galaxy the rules of proxy. You can also you know you customized You can also for this hour and then create Douro and roll and then customize it or for now we're going to just make changes to the proxied or to see if you to that that to template here. Let's examine this template and if you scroll down to the bottom of it and this is where the you know the configuration for back in servers are being done just you know full screen this and this is where it is being generated. So we have back in servers and is back in service at your proxy and back and so are the values that come from the variable that we define as part of our we have defined it as part of group first. You can do it in multiple places and if you go to the galaxies that your proxy rule and look at that variable description this is where it has been defined as a proxy and it's called back in and this goes over whatever you do find there. It gets added here. That's where the name and address for backing comes from. So this is like trading over stuff back in. Now we want to know what the list of hosts in our group called as apps over so we're going to use for host in group that's another variable that we could use as part of if you look at the magic variables example we can use that and we're going to do it over a group of forced from our inventory so that sales groups. And this is then went to group in that we have defined the observer's inventory. That's what is going to rate over and for host in-groups app. Now this back in name we change it with a magic variable and that's where we use data using coastwise. We've seen the example of force twice earlier but we start using it right here and we're going to get the host to ours for the whole tossed in that hydration for hosting groups. And then we defined which variable that would fetch from that host. And if it has been cached all year it will get fetch from there. So it's ansible hostname. That's what we all do out there. And similarly be copied and pasted here and we want to fetch. This time it's the IP IP address so it's going to be danceable underscore eat zero IPV for it's a multi level variable. So we use those brackets to define it. It's IPV for an address the same variable that we looked at earlier. That's the one on the bottom that's IPV for and address as danceable. Zero IPV 4 and the address. Let's add that here. So it's the host answerability IPV for address. We also need to define the board that it listens to. So port 80. That's very important Don't miss that port part. And again the hostname the same as the first of the first magic failure rates so. Host. Host ansible hostname we just copy and paste that same string here. Now this will allow us to iterate over our holes so whichever hosts are available at that point of time when you're running a playbook it will take that fetch. It's ve