working with inventories

This commit is contained in:
Ilgar_Naghiyev
2020-02-28 12:38:29 +01:00
parent 7240039ae7
commit 51703d125d

View File

@@ -14,6 +14,8 @@ Red Hat Certified Specialist in Ansible Automation (EX407) Preparation Course
- [Inventory Management](#inventory-management) - [Inventory Management](#inventory-management)
- [Inventory Essentials and Inventory Variables](#inventory-essentials-and-inventory-variables) - [Inventory Essentials and Inventory Variables](#inventory-essentials-and-inventory-variables)
- [Demo: Variables and Inventories](#demo-variables-and-inventories) - [Demo: Variables and Inventories](#demo-variables-and-inventories)
- [Demo: Using YAML in Inventories](#demo-using-yaml-in-inventories)
## Understanding Core Components of Ansible ## Understanding Core Components of Ansible
### Understanding Core Components of Ansible Part 1 ### Understanding Core Components of Ansible Part 1
@@ -360,3 +362,42 @@ In Ansible, inventories are crucially important as they serve as the foundation
### Demo: Variables and Inventories ### Demo: Variables and Inventories
Being able to work with inventories and variables is an essential skill for any user of Ansible. This command line demonstration will show students the best practices for using variables within inventories. Being able to work with inventories and variables is an essential skill for any user of Ansible. This command line demonstration will show students the best practices for using variables within inventories.
Inside of **inventory** directory we have following structure:
```
[cloud_user@innaghiyev2c inventory]$ ls -l
total 4
drwxrwxr-x. 2 cloud_user cloud_user 23 Feb 28 05:18 group_vars
drwxrwxr-x. 2 cloud_user cloud_user 25 Feb 27 10:53 host_vars
-rw-rw-r--. 1 cloud_user cloud_user 127 Feb 27 10:41 inventory
```
Where:
- `inventory` - stores our hosts
```
[cloud_user@innaghiyev2c inventory]$ cat inventory
innaghiyev1c ansible_host=innaghiyev1c.mylabserver.com
[labservers]
innaghiyev3c.mylabserver.com
innaghiyev1c.mylabserver.com
```
- `group_vars` - contains group name of our hosts' group. `labservers` - name of group, which contains variables
```
[cloud_user@innaghiyev2c inventory]$ ls -l group_vars/
total 4
-rw-rw-r--. 1 cloud_user cloud_user 50 Feb 28 05:18 labservers
[cloud_user@innaghiyev2c inventory]$ cat group_vars/labservers
logs : /var/log/messages
secure : /var/log/secure
```
- `host_vars` - contains hostname with stored variable inside. `innaghiyev1c` - name of the host, which contains variables
```
[cloud_user@innaghiyev2c inventory]$ ls host_vars/
innaghiyev1c
[cloud_user@innaghiyev2c inventory]$ cat host_vars/innaghiyev1c
opt_dir : /opt
```
### Demo: Using YAML in Inventories