To create parent/child relationships for groups: This approach reduces maintenance because you can add or remove hosts from the parent group by editing the child groups. For example, if all your production hosts are already in groups such as atlanta_prod and denver_prod, you can create a production group that includes those smaller groups. Parent groups are also known as nested groups or groups of groups. You can create parent/child relationships among groups. Grouping groups: parent/child group relationships You can see that exists in the dbservers, east, and prod groups. Ungrouped : hosts : : webservers : hosts : : : dbservers : hosts : : : : east : hosts : : : : west : hosts : : : prod : hosts : : : : test : hosts : : : When - The development stage, to avoid testing on production resources (for example, prod, test).Įxtending the previous YAML inventory to include what, when, and where would look like this: Where - A datacenter or region, to talk to local DNS, storage, and so on (for example, east, west). What - An application, stack or microservice (for example, database servers, web servers, and so on). For example, a production web server in a data center in Atlanta might be included in groups called and and. You can put each host in more than one group. Though all and ungrouped are always present, they can be implicit and not appear in group listings like group_names. For example, in the basic inventory above, the host belongs to the all group and the ungrouped group the host belongs to the all group and the dbservers group. The ungrouped group contains all hosts that don’t have another group aside from all.Įvery host will always belong to at least 2 groups ( all and ungrouped or all and some other group). Ungrouped : hosts : : webservers : hosts : : : dbservers : hosts : : : : Default groups Įven if you do not define any groups in your inventory file, Ansible creates two default groups: all and ungrouped. A basic INI /etc/ansible/hosts might look like this: The most common formats are INI and YAML. You can create your inventory file in one of many formats, depending on the inventory plugins you have. Inventory basics: formats, hosts, and groups Inheriting variable values: group variables for groups of groupsĬonnecting to hosts: behavioral inventory parameters Grouping groups: parent/child group relationshipsĪssigning a variable to one machine: host variablesĪssigning a variable to many machines: group variables Inventory basics: formats, hosts, and groups You can use multiple sources for inventory, including both dynamic inventory and static files. For example, you can use a dynamic inventory plugin to list resources in one or more cloud providers. These can use different formats (YAML, ini, and so on). You can create a directory with multiple inventory files. Here are three options beyond the /etc/ansible/hosts file: As your inventory expands, you may need more than a single file to organize your hosts and groups. You can specify a different inventory file at the command line using the -i option or in configuration using inventory.Īnsible Inventory plugins supports a range of formats and sources to make your inventory flexible and customizable. The default location for this file is /etc/ansible/hosts. The simplest inventory is a single file with a list of hosts and groups. Once your inventory is defined, you use patterns to select the hosts or groups you want Ansible to run against. Your inventory defines the managed nodes you automate, with groups so you can run automation tasks on multiple hosts at the same time. You can pass host names at the command line, but most Ansible users create inventory files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |