Ansible Inventory tutorial YAML INI – Ansible tutorial for beginners
Working with Ansible inventories in YAML or INI formats.
Please consider supporting my channel:
Order services:
Bizanosa WordPress Support Service : https://bizanosa.com/wordpress-suppor...
Bizanosa VPS Support service : https://bizanosa.com/web-server-servi...
Donate:
https://paypal.me/rwahowa
https://www.buymeacoffee.com/bizanosa
Part of the captions
In this part, let's talk about Ansible inventory. So, what is an inventory? An inventory is a list of all your hosts, a list of hosts that Ansible will be working with. Your Ansible inventory file could be in YAML format or it could be INI. So, this is a sample INI file, a sample INI format, and you can see this just lists the different hosts. And this is a way to group them. So, these are two servers that are grouped under web server, and then this also is another grouping of DB servers; they've been grouped there. So, this is something you can do; you can group your servers, and you can see this one is ungrouped. So, this is INI format. If you see any file inventory file that is like this, that is INI format. In YAML, you can also create a YAML format. Let me bring this out in YAML. You'll see that the ungrouped host will look like this, and the other grouped ones will be like this. The point is you can have either a YAML inventory or INI inventory. In most cases, you're going to find that most people just use the INI format, and they only use the YAML format if they're creating dynamic inventories that will be used programmatically at some point, because it's much easier to work programmatically with YAML than it would be to work with an INI inventory.
Bring this back; let's hide it under that default host. So, you have a default host when you install Ansible. You will have a default host file, and you can use this host file. But usually, you'll find that you'll just create your own inventory file that you can use. Depending on how you installed Ansible, you may find that this file doesn't exist for you. It may be in a different path. If you installed Ansible via Python pip, then it may be in a different location than someone who installed using apt. In our setup, we installed it using the apt package manager.
Come back to the notes, and I told you these notes are available for you. You just go to this link, and you can copy any code that you need to copy. So, for here, let's check if we have this default inventory file. I will just open up Ubuntu 22.04 our WSL setup. We can open this; we can even open it with Visual Studio Code. Control + Shift + V. So, if Control + Shift + V doesn't work for you on your WSL, come here under settings, properties, and use Control + Shift + V, enable that. Code, etc., and we'll open that using VS Code. You can see this is our default inventory. So, let's just go through it a bit, and you can see this is a default Ansible host file. It should leave in that location. So, comments begin with that. Blank lines are ignored. Groups of hosts are delimited by a header. You can enter host names or IP addresses. A host name or IP can be a member of multiple groups, and we're going to see that as well at some point. So, example one, ungrouped hosts. These are ungrouped hosts. You can see they don't have this at the top. If they have this at the top, it means that they've been grouped as web servers. You have web servers here. You can see that is a host name. That is a host name, and that is an IP address. So, you can use either, but just remember if you're using a host name, then you need to add some DNS records to ensure that this is reachable. Otherwise, just use the IP address. If you have multiple hosts following a pattern, you can specify them like this. So, WW16, this simply means that ww.example.com WW2 up to 006.example.com. And the same is true for this one as well.
So, that's just another grouping of DB servers. You can group them like that if you have web servers, DB servers, mail servers, you can group them based on locations. We're going to talk about that in a moment. So, that's our default host file. If you installed Ansible using sudo apt install as indicated here, if you installed it using this step, then you can find your host file, your default host file under /etc/ansible/host. You'll find it there. Go back to inventories. Come back here. So, we have spoken about this. Oh yeah, you can also list your host files. Ansible all --list-hosts. Now, here, you'll see that we have Ansible all hosts, and then we have the same with a -i inventory file. So, the -i tells Ansible which inventory to work with. In this case, if you do this, it's going to go for the default host file.
***Support My Channel***
If this video was helpful to you, consider supporting my channel : https://paypal.me/rwahowa
I will greatly appreciate your support.
SOCIAL :
Facebook : fb.com/bizanosa
Website : https://bizanosa.com
Информация по комментариям в разработке