Abstract
| Goal |
Create inventories of machines to manage, and configure credentials necessary for automation controller's execution nodes to log in and run Ansible jobs on those systems. |
| Objectives |
|
| Sections |
|
| Lab |
|
An Ansible inventory is a list of managed hosts in your infrastructure on which you run your automation tasks. Those managed hosts can be organized into groups that can be used to specify subsets of managed hosts on which you run particular plays. The inventory can also be used to define host and group variables that apply to those hosts and are used by your plays.
With ansible-navigator, you might have defined your inventory in a text file, in either INI or YAML format, and then specified which inventory file to use on the command line or with an ansible.cfg file. The following is an example of an inventory file in INI format.
[production_servers] prod1.example.com prod2.example.com [database_servers] db_server01.example.com [production_servers:vars] apache_listen_port=8080 apache_root_path=/var/www/mywebdocs/ [all:vars] ansible_user=student ansible_ssh_private_key_file=/home/student/.ssh/id_rsa
In order to run automation jobs with automation controller, you must specify an inventory for the job. There are several ways to do this, including:
By configuring the inventory through the web UI.
By managing the inventory as a static file in a Git repository.
By dynamically generating the inventory from an external source.
This section covers how to configure, inspect, and edit a static inventory using the automation controller web UI.
Automation controller manages inventories as objects. Each organization might have many inventories available. Users can create job templates and configure those job templates to use a specific inventory belonging to the organization. Access to an inventory object on the automation controller depends on the roles a user has been assigned for the inventory.
Your automation controller license determines the maximum number of hosts you can define in your inventory. If you exceed that number in your inventory, automation controller will not launch jobs. If a dynamic inventory sync causes automation controller to exceed the managed node count specified in its license, the dynamic inventory sync fail.
If you have multiple hosts in your inventory that have the same name, such as webserver1, they count for licensing purposes as a single node. Note that this differs from the count on the Dashboard, which counts hosts in separate inventories separately. Note that this behavior is case-sensitive; webserver1 and WebServer1 are treated as different nodes.
In the automation controller web UI, click in the left pane and select from the page to verify how many hosts your license supports and how many are remaining.
Use the following procedure to create inventories within each organization:
Log in to the automation controller web UI as the admin user, or as a user assigned the Admin or Inventory Admin role for the organization under which you intend to create the new inventory.
Click → and then click .
Select .
Enter a name and a description for the new inventory in the and fields, respectively.
Use the organization, or click the search icon to select a different organization for the inventory.
Similarly, click the search icon under to select instance groups.
Click .
On the inventory page, click and then click .
Enter a name and description for the new group in the and fields, respectively.
Click .
You can assign appropriate RBAC roles to users and teams for an inventory, in order to grant users the ability to read, use, or manage it.
The following is a list of available roles for an inventory:
| Roles | Description |
|---|---|
|
Grants users full permissions over an inventory. These permissions include deleting and modifying an inventory. In addition, this role also grants permissions associated with the inventory roles | |
| Grants users the ability to update a dynamic inventory from its external data source. | |
|
Grants users the ability to use the inventory to execute ad hoc commands. Using Ansible automation controller for ad hoc command execution is discussed in detail in the Ansible automation controller User Guide. | |
|
Grants users the ability to use an inventory in a job template resource. This controls which inventory is used to start jobs using the job template’s playbook. | |
| Grants users the ability to view the contents of an inventory. |
When you create an inventory, it is only accessible by users who have the Admin, Inventory Admin, or Auditor roles for the organization to which the inventory belongs. You have to configure access to all other users.
First, you need to create the inventory and save it, and after that, you can assign users and teams appropriate roles as discussed previously.
Use the following procedure to assign users and teams roles on an inventory:
Log in to the automation controller web UI as the admin user or as a user assigned the Admin or Inventory Admin role for the organization in which you intend to modify the permissions of an inventory.
Click → .
Click the inventory.
Click and then click .
Click either or and then click .
Select the users or teams from the list and then click .
Select one or more roles by clicking on them.
Click to complete the new roles.
Ansible supports inventory variables that apply values to variables on particular hosts or host groups.
When you manage a static inventory in the Ansible automation controller web UI, you can define inventory variables directly in the inventory object.
On the page, set the variables by clicking the (pencil) icon next to the inventory name. On the page for the inventory, you can set variables that affect all hosts in the inventory:
When creating a host group within an inventory, you can define the group variables using YAML or JSON in the field on the page.
You can also set the group variables by clicking on the (pencil) icon next to the host group’s name in the inventory. These variables apply to all hosts that are part of the group:
Likewise, you can define the host variables using either YAML or JSON in the field on the page when an individual host is created within an inventory. Alternatively, click the (pencil) icon next to the host name in the inventory to define the host variables. Variables defined in this manner only apply to the specific host.
Other variables with higher precedence override inventory variables. Extra variables defined in a job template and playbook variables have higher precedence than inventory variables.
How to build your inventory https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#intro-inventory
A discussion of how node counting works for licenses is available at https://docs.ansible.com/ansible-tower/latest/html/administration/license-support.html#node-counting-in-licenses