Documentation

15. Inventories

An Inventory is a collection of hosts against which jobs may be launched, the same as an Ansible inventory file. Inventories are divided into groups and these groups contain the actual hosts. Groups may be sourced manually, by entering host names into Tower, or from one of Ansible Tower’s supported cloud providers.

Note

If you have a custom dynamic inventory script, or a cloud provider that is not yet supported natively in Tower, you can also import that into Tower. Refer to Inventory File Importing in the Ansible Tower Administration Guide.

This tab displays a list of the inventories that are currently available. The inventory list may be sorted and searched by Name, Type, or Organization.

Inventories - home with examples

The list of Inventory details includes:

  • Inventory Sync (sync-button): Green indicates successful syncs in the inventory, and red indicates failed syncs. Clicking this icon displays the sync status for the last five inventory source syncs and source information, if the inventory has sources that are able to sync.

_images/inventories-home-with-status.png
  • Status Dot: This shows the status of recent jobs for this inventory.

  • Name: The inventory name. Clicking the Inventory name navigates to the properties screen for the selected inventory, which shows the inventory’s groups and hosts. (This view is also accessible from the edit button icon.)

  • Type: Identifies whether it is a standard inventory or a Smart Inventory.

  • Organization: The organization to which the inventory belongs.

  • Actions: The following actions are available for the selected inventory:

    • Edit (edit button): Edit the properties for the selected inventory

    • Copy (copy): Makes a copy of an existing inventory as a template for creating a new one

    • Delete (delete): Delete the selected inventory. This operation cannot be reversed!

Note

If deleting items that are used by other work items, a message opens listing the items are affected by the deletion and prompts you to confirm the deletion. Some screens will contain items that are invalid or previously deleted, so they will fail to run. Below is an example of such a message:

_images/warning-deletion-dependencies.png

15.1. Smart Inventories

A Smart Inventory is a collection of hosts defined by a stored search that can be viewed like a standard inventory and made to be easily used with job runs. Organization administrators have admin permission to inventories in their organization and can create Smart Inventories. A Smart Inventory is identified by KIND=smart. You can define a Smart Inventory using the same method being used with Tower Search. InventorySource is directly associated with an Inventory.

The Inventory model has the following new fields that are blank by default but are set accordingly for Smart Inventories:

  • kind is set to smart for Smart Inventories

  • host_filter is set AND kind is set to smart for Smart Inventories.

The host model has a related endpoint, smart_inventories that identifies a set of all the Smart Inventory a host is associated with. The membership table is updated every time a job runs against a smart inventory.

Note

To update the memberships more frequently, you can change the file-based setting AWX_REBUILD_SMART_MEMBERSHIP to True (default is False). This will update memberships in the following events:

  • a new host is added

  • an existing host is modified (updated or deleted)

  • a new Smart Inventory is added

  • an existing Smart Inventory is modified (updated or deleted)

You can view actual inventories without being editable:

  • Names of Host and Group created as a result of an inventory source sync

  • Group records cannot be edited or moved

You cannot create hosts from a Smart Inventory host endpoint (/inventories/N/hosts/) as with a normal inventory. The administrator of a Smart Inventory has permission to edit fields such as the name, description, variables, and the ability to delete, but does not have the permission to modify the host_filter, because that will affect which hosts (that have a primary membership inside another inventory) are included in the smart inventory. Note, host_filter only apply to hosts inside of inventories inside of the Smart Inventory’s organization.

In order to modify the host_filter, you need to be the organization administrator of the inventory’s organization. Organization admins already have implicit “admin” access to all inventories inside the organization, therefore, this does not convey any permissions they did not already possess.

Administrators of the Smart Inventory can grant other users (who are not also admins of your organization) permissions like “use” “adhoc” to the smart inventory, and these will allow the actions indicate by the role, just like other standard inventories. However, this will not give them any special permissions to hosts (which live in a different inventory). It will not allow them direct read permission to hosts, or permit them to see additional hosts under /#/hosts/, although they can still view the hosts under the smart inventory host list.

In some situations, you can modify the following:

  • A new Host manually created on Inventory w/ inventory sources

  • In Groups that were created as a result of inventory source syncs

  • Variables on Host and Group are changeable

Hosts associated with the Smart Inventory are manifested at view time. If the results of a Smart Inventory contains more than one host with identical hostnames, only one of the matching hosts will be included as part of the Smart Inventory, ordered by Host ID.

15.2. Inventory Plugins

Starting in 3.5, Ansible Tower running Ansible 2.8 automatically switches to using inventory plugins (as opposed to scripts), depending on the source type. The plugins that are enabled in Ansible 2.8 are:

The following are not running plugins and are still using scripts:

If you already have an inventory source set up, then Tower automatically switches to use the inventory plugins depending on the source and Ansible version, but continue to maintain the same content previously in those scripts. If you need to control the version of Ansible being used, you can use custom virtual environments for the inventory source. Refer to Using virtualenv with Ansible Tower.

15.3. Add a new inventory

Adding a new inventory involves several components. Click below to jump to a specific component:

To create a new inventory or Smart Inventory:

  1. Click the add button, and select the type of inventory to create.

The type of inventory is identified by the labels and the row of tabs across the top of the create form.

Inventories_create_new - create new inventory

  1. Enter the appropriate details into the following fields:

  • Name: Enter a name appropriate for this inventory.

  • Description: Enter an arbitrary description as appropriate (optional).

  • Organization: Required. Choose among the available organizations.

  • Smart Host Filter: (Only applicable to Smart Inventories) Click the search button to open a separate Dynamic Hosts window to filter hosts for this inventory. These options are based on the organization you chose.

    Filters are similar to tags in that tags are used to filter certain hosts that contain those names. Therefore, to populate the Smart Host Filter field, you are specifying a tag that contains the hosts you want, not actually selecting the hosts themselves. Enter the tag in the Search field and press [Enter]. Filters are case-sensitive. Refer to the Smart Host Filter section for more information.

    _images/inventories-create-new-inventory-dynamic-hosts.png
  • Insights Credential: (Only applicable to standard inventories) Enter the appropriate Insights credential if the inventory is used with Insights.

  • Instance Groups: Click the search button to open a separate window. Choose the instance groups for this inventory to run on. If the list is extensive, use the search to narrow the options.

  • Variables: Variable definitions and values to be applied to all hosts in this inventory. Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.

Inventories_create_new_saved - create new inventory

  1. Click Save when done.

After Tower saves the new inventory, you can proceed with configuring permissions, groups, hosts, sources, and view completed jobs, if applicable to the type of inventory. For more instructions, refer to the subsequent sections.

15.3.1. Add permissions

The Permissions tab allows you to review, grant, edit, and remove associated permissions for users as well as team members. To assign permissions to a particular user for this resource:

  1. Click the Permissions tab.

  2. Click the add button to open the Add Users/Teams window.

Add Permissions Form
  1. Specify the users or teams that will have access then assign them specific roles:

  1. Click to select one or multiple check boxes beside the name(s) of the user(s) or team(s) to select them.

Note

You can select multiple users and teams at the same time by navigating between the Users and Teams tabs without saving.

After selections are made, the window expands to allow you to select a role from the drop-down menu list for each user or team you chose.

Roles Assignment for Selected Users

The example above shows options associated with inventories. Different resources have different options available:

  • Admin allows read, run, and edit privileges (applies to all resources)

  • Use allows use of a resource in a job template (applies all resources except job templates)

  • Update allows updating of project via the SCM Update (applies to projects and inventories)

  • Ad Hoc allows use of Ad Hoc commands (applies to inventories)

  • Execute allows launching of a job template (applies to job templates)

  • Read allows view-only access (applies to all resources)

Tip

Use the Key button in the roles selection pane to display a description of each of the roles. For more information, refer to the Roles section of this guide.

  1. Select the role to apply to the selected user or team.

Note

You can assign roles to multiple users and teams by navigating between the Users and Teams tabs without saving.

Add Permissions - Examples of users and teams selected
  1. Review your role assignments for each user and team.

Add Permissions - Examples of roles applied
  1. Click Save when done, and the Add Users/Teams window closes to display the updated roles assigned for each user and team.

    Permissions tab with Role Assignments

To remove Permissions for a particular user, click the Disassociate (x) button next to its resource.

_images/permissions-disassociate.png

This launches a confirmation dialog, asking you to confirm the disassociation.

_images/permissions-disassociate-confirm.png

15.3.2. Add groups

Inventories are divided into groups, which may contain hosts and other groups, and hosts. Groups are only applicable to standard inventories and is not a configurable directly through a Smart Inventory. You can associate an existing group through host(s) that are used with standard inventories. There are several actions available for standard inventories:

  • Create a new Group

  • Create a new Host

  • Run a command on the selected Inventory

  • Edit Inventory properties

  • View activity streams for Groups and Hosts

  • Obtain help building your Inventory

Note

Starting in Ansible Tower 3.2, inventory sources are no longer associated with groups. Prior versions, spawned groups and hosts would be children of our inventory source group. Now, spawned groups are top-level. These groups may still have child groups, and all of these spawned groups may have hosts.

To create a new group for an inventory:

  1. Click the add button to open the Create Group window.

Inventories_manage_group_add

  1. Enter the appropriate details into the required and optional fields:

  • Name: Required

  • Description: Enter an arbitrary description as appropriate (optional)

  • Variables: Enter definitions and values to be applied to all hosts in this group. Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.

  1. When done, click Save.

15.3.2.1. Add groups within groups

To add groups within groups:

  1. Click the Groups tab.

  2. Click the add button, and select whether to add a group that already exists in your configuration or create a new group.

  3. If creating a new group, enter the appropriate details into the required and optional fields:

  • Name: Required

  • Description: Enter an arbitrary description as appropriate (optional)

  • Variables: Enter definitions and values to be applied to all hosts in this group. Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.

  1. When done, click Save.

The Create Group window closes and the newly created group displays as an entry in the list of groups associated with the group that it was created for.

Inventories add group subgroup

If you chose to add an existing group, available groups will appear in a separate selection window.

Inventories add group existing subgroup

Once a group is selected, it displays as an entry in the list of groups associated with the group.

5. To configure additional groups and hosts under the subgroup, click on the name of the subgroup from the list of groups and repeat the same steps described in this section.

Inventories add group subgroup emphasized

15.3.2.2. View or edit inventory groups

Starting in Ansible Tower 3.5, you can view all your inventory groups at once, or you can filter it to only display the root group(s). An inventory group is considered a root group if it is not a subset of another group.

_images/inventories-groups-all-groups-view.png _images/inventories-groups-root-groups-view.png

You may be able to delete a subgroup without concern for dependencies, but if you want to delete a root group, Tower will look for dependencies such as any child groups or hosts. If the root group you want to delete has both, a confirmation dialog displays for you to choose whether to delete the root group and all of its subgroups and hosts; or promote the subgroup(s) so they become the top-level inventory group(s), along with their host(s).

_images/inventories-groups-delete-root-with-children.png

If the root group has a subgroup that does not have any hosts, the confirmation dialog simply asks if you want to delete everything; or promote your group.

_images/inventories-groups-delete-root-with-child.png

15.3.3. Add hosts

You can configure hosts for the inventory as well as for groups and groups within groups. To configure hosts:

  1. Click the Hosts tab.

  2. Click the add button, and select whether to add a host that already exists in your configuration or create a new host.

  3. If creating a new host, select the toggle button button to specify whether or not to include this host while running jobs.

  1. Enter the appropriate details into the required and optional fields:

  • Host Name: Required

  • Description: Enter an arbitrary description as appropriate (optional)

  • Variables: Enter definitions and values to be applied to all hosts in this group. Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.

  1. When done, click Save.

The Create Host window closes and the newly created host displays as an entry in the list of hosts associated with the group that it was created for.

Inventories add group host

Note

You may also run ad hoc commands from this screen. Refer to Running Ad Hoc Commands for more detail.

If you chose to add an existing host, available hosts will appear in a separate selection window.

Inventories add existing host

Once a host is selected, it displays as an entry in the list of hosts associated with the group.

6. To configure facts and additional groups for the host, click on the name of the host from the list of hosts.

Inventories add group host emphasized

This opens the Details tab of the selected host.

Inventories add group host details

  1. Click the Facts tab to input facts you want to gather. Refer to the Fact Caching section for more information about facts.

  2. Click the Groups tab to configure groups for the host.

  1. Click the add button to associate the host with an existing group.

Available groups appear in a separate selection window.

_images/inventories-add-group-hosts-add-groups.png
  1. Click to select the group(s) to associate with the host and click Save.

Once a group is associated, it displays as an entry in the list of groups associated with the host.

  1. If a host was used to run a job, you can view details about those jobs in the Completed Jobs tab of the host and click Expanded to view details about each job.

_images/inventories-add-host-view-completed-jobs.png

15.3.4. Add source

Inventory sources are no longer associated with groups. Prior to Ansible Tower 3.2, spawned groups and hosts would be children of our inventory source group. Now, spawned groups are top-level. These groups may still have child groups, and all of these spawned groups may have hosts.

Adding a source to an inventory only applies to standard inventories. Smart inventories inherit their source from the standard inventories they are associated with. To configure the source for the inventory:

  1. In the inventory you want to add a source, click the Sources tab.

  2. Click the add button.

This opens the Create Source window.

Inventories create source

  1. Enter the appropriate details into the required and optional fields:

  • Name: Required

  • Description: Enter an arbitrary description as appropriate (optional)

  • Source: Choose a source for your inventory. Refer to the Inventory Sources section for more information about each source and details for entering the appropriate information. Starting with Ansible Tower version 3.2, support for Rackspace Cloud Servers was discontinued.

  • Ansible Environment: This field is only present if custom virtual environments (venvs) are setup. Choose the venv with which you want to run your inventory imports. Refer to Using virtualenv with Ansible Tower for details on setting up a custom venvs.

_images/inventories-edit-source-details-venv.png
  1. After completing the required information for your chosen inventory source, you can configure the level of output on any inventory source’s update jobs by selecting the appropriate option from the Verbosity drop-down menu.

  2. All cloud inventory sources have the following update options:

  • Overwrite: If checked, any hosts and groups that were previously present on the external source but are now removed, will be removed from the Tower inventory. Hosts and groups that were not managed by the inventory source will be promoted to the next manually created group, or if there is no manually created group to promote them into, they will be left in the “all” default group for the inventory.

When not checked, local child hosts and groups not found on the external source will remain untouched by the inventory update process.

  • Overwrite Variables: If checked, all variables for child groups and hosts will be removed and replaced by those found on the external source. When not checked, a merge will be performed, combining local variables with those found on the external source.

  • Update on Launch: Each time a job runs using this inventory, refresh the inventory from the selected source before executing job tasks. To avoid job overflows if jobs are spawned faster than the inventory can sync, selecting this allows you to configure a Cache Timeout to cache prior inventory syncs for a certain number of seconds.

The “Update on Launch” setting refers to a dependency system for projects and inventory, and it will not specifically exclude two jobs from running at the same time. If a cache timeout is specified, then the dependencies for the second job is created and it uses the project and inventory update that the first job spawned. Both jobs then wait for that project and/or inventory update to finish before proceeding. If they are different job templates, they can then both start and run at the same time, if the system has the capacity to do so. If you intend to use Tower’s provisioning callback feature with a dynamic inventory source, “Update on Launch” should be set for the inventory group.

  1. Review your entries and selections and click Save when done. This allows you to configure additional details, such as notifications and schedules.

Note

The Notifications tab is only present after you save the newly-created source.

_images/inventories-create-source-with-notifications-tab.png
  1. To configure notifications for the source, click the Notifications tab.

  1. If notifications are already set up, use the toggles to enable or disable the notifications to use with your particular source. For more detail, see Enable and Disable Notifications.

  2. if notifications have not been set up, refer to Notifications for more information.

  1. To configure schedules associated with this inventory source, click the Schedules tab.

  1. If schedules are already set up; review, edit, or enable/disable your schedule preferences.

  2. if schedules have not been set up, refer to Schedules for more information.

  1. Review your entries and selections and click Save when done.

Once a source is defined, it displays as an entry in the list of sources associated with the inventory. From the Sources tab you can perform a sync on a single source, or sync all of them at once. You can also perform additional actions such as scheduling a sync process, and edit or delete the source.

Inventories view sources

15.3.4.1. Inventory Sources

Choose a source which matches the inventory type against which a host can be entered:

15.3.4.1.1. Sourced from a Project

An inventory that is sourced from a project means that is uses the SCM type from the project it is tied to. For example, if the project’s source is from GitHub, or a Red Hat Insights project, then the inventory will use the same source.

  1. To configure a project-sourced inventory, select Sourced from a Project from the Source field.

  2. The Create Source window expands with additional fields. Enter the following details:

  • Credential: Optionally specify the credential to use for this source.

  • Project: Required. Specify the project this inventory is using as its source. Click the search button to choose from a list of projects. If the list is extensive, use the search to narrow the options.

  • Inventory File: Required. Select an inventory file associated with the sourced project. If not already populated, you can type it into the text field within the drop down menu to filter the extraneous file types. In addition to a flat file inventory, you can point to a directory or an inventory script.

_images/inventories-create-source-sourced-from-project-filter.png
  1. In addition to the update options available for cloud inventory sources, you can specify whether or not to update on project changes. Check the Update on Project Update option to refresh the inventory from the selected source after every project update where the SCM revision changes before executing job tasks. For more detail, refer to Update on Project Update in the Ansible Tower Administration Guide.

  2. In order to pass to the custom inventory script, you can optionally set environment variables in the Environment Variables field.

Inventories - create source - sourced from project example

Note

If you are executing a custom inventory script from SCM, please make sure you set the execution bit (i.e. chmod +x) on the script in your upstream source control. If you do not, Tower will throw a [Errno 13] Permission denied error upon execution.

15.3.4.1.2. Amazon Web Services EC2
  1. To configure an AWS EC2-sourced inventory, select Amazon EC2 from the Source field.

  2. The Create Source window expands with additional fields. Enter the following details:

  • Credential: Optionally choose from an existing credential (for more information, refer to Credentials).

    If Tower is running on an EC2 instance with an assigned IAM Role, the credential may be omitted, and the security credentials from the instance metadata will be used instead. For more information on using IAM Roles, refer to the IAM_Roles_for_Amazon_EC2_documentation_at_Amazon.

  • Regions: Click on the regions field to see a list of regions for your cloud provider. You can select multiple regions, or choose “All” to include all regions. Tower will only be updated with Hosts associated with the selected regions.

  • Instance Filters: Rather than importing your entire Amazon EC2 inventory, filter the instances returned by the inventory script based on a variety of metadata. Hosts are imported if they match any of the filters entered here.

Examples:

  • To limit to hosts having the tag TowerManaged: Enter tag-key=TowerManaged

  • To limit to hosts using either the key-name staging or production: Enter key-name=staging, key-name=production

  • To limit to hosts where the Name tag begins with test: Enter tag:Name=test*

For more information on the filters that can be used here, refer to the Describe Instances documentation at Amazon.

  • Only Group By: By default, Tower creates groups based on the following Amazon EC2 parameters:

    • Availability Zones

    • Image ID

    • Instance ID

    • Instance Type

    • Key Name

    • Region

    • Security Group

    • Tags (by name)

    • VPC ID

    • Tag None

    If you do not want all these groups created, select from the dropdown the list of groups that you would like created by default. You can also select Instance ID to create groups based on the Instance ID of your instances.

  1. Use the Source Variables field to override variables found in ec2.ini and used by the inventory update script. Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two. For a detailed description of these variables view ec2.ini in the Ansible Collections GitHub repo.

Inventories - create source - AWS EC2 example

15.3.4.1.3. Google Compute Engine
  1. To configure a Google-sourced inventory, select Google Compute Engine from the Source field.

  2. The Create Source window expands with additional fields. Enter the following details:

  • Credential: Required. Choose from an existing Credential. For more information, refer to Credentials.

  • Regions: Click on the regions field to see a list of regions for your cloud provider. You can select multiple regions, or choose “All” to include all regions. Tower will only be updated with Hosts associated with the selected regions.

Inventories - create source - GCE example

15.3.4.1.4. Microsoft Azure Resource Manager
  1. To configure a Azure Resource Manager-sourced inventory, select Microsoft Azure Resource Manager from the Source field.

  2. The Create Source window expands with additional fields. Enter the following details:

  • Credential: Required. Choose from an existing Credential. For more information, refer to Credentials.

  • Regions: Click on the regions field to see a list of regions for your cloud provider. You can select multiple regions, or choose “All” to include all regions. Tower will only be updated with Hosts associated with the selected regions.

Inventories - create source - Azure RM example

15.3.4.1.5. VMware vCenter
  1. To configure a VMWare-sourced inventory, select VMware vCenter from the Source field.

  2. The Create Source window expands with additional fields. Enter the following details:

  • Credential: Required. Choose from an existing credential (for more information, refer to Credentials).

  • Instance Filters: Rather than importing your entire VMWare inventory, filter the instances returned by the inventory script based on a variety of metadata. Hosts are imported if they match any of the filters entered here.

For more information on the filters that can be used here, refer to the Quick Filters Available for vSphere Objects documentation at VMware.

  • Only Group By: By default, Tower creates groups based on user-specified VMWare parameters. For example, enter Instance ID to create groups based on the Instance ID of your instances.

  1. Use the Source Variables field to override variables found in vmware_inventory.ini and used by the inventory update script. Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two. For a detailed description of these variables, view the vmware_inventory.ini file in the Ansible GitHub repo.

Note

The inventory script for VMware was updated in Ansible Tower 3.1.2 to allow configuration of the host_filters or groupby_patterns parameter. Specify those values in the Source Variables text field of the Create Group screen or Edit Group screen. For example:

_images/inventories-create-vmware-group-source-variables.png

Inventories - create source - VMWare example

15.3.4.1.6. Red Hat Satellite 6
  1. To configure a Red Hat Satellite-sourced inventory, select Red Hat Satellite from the Source field.

  2. The Create Source window expands with additional fields.

  • Credential: Required. Choose from an existing credential (for more information, refer to Credentials).

  • Use the Source Variables field to override variables found in foreman.ini and used by the inventory update script.

Note

The variable want_facts from foreman.ini is hard-coded to True and cannot be overridden at this time. If you want to set the group_patterns, group_prefix, or want_hostcollections variables, prefix them with satellite6, e.g.: satellite6_group_prefix: myprefix

Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two. For a detailed description of these variables view foreman.ini in the Ansible Collections GitHub repo.

Inventories - create source - RH Satellite example

15.3.4.1.7. Red Hat CloudForms
  1. To configure a Red Hat CloudForms-sourced inventory, select Red Hat CloudForms from the Source field.

  2. The Create Source window expands with additional fields. Enter the following details:

  • Credential: Required. Choose from an existing credential (for more information, refer to Credentials).

  • Use the Source Variables field to override variables found in cloudforms.ini and used by the inventory update script. Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two. For a detailed description of these variables view cloudforms.ini in the Ansible Collections GitHub repo.

Inventories - create source - RH CloudForms example

15.3.4.1.8. OpenStack
  1. To configure an OpenStack-sourced inventory, select OpenStack from the Source field.

  2. The Create Source window expands with additional fields. Enter the following details:

  • Credential: Required. Choose from an existing credential (for more information, refer to Credentials).

  • Use the Source Variables field to override variables found in openstack.yml and used by the inventory update script. Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two. For a detailed description of these variables view openstack.yml in the Ansible GitHub repo.

Inventories - create source - OpenStack example

15.3.4.1.9. Red Hat Virtualization
  1. To configure a Red Hat Virtualization-sourced inventory, select Red Hat Virtualization from the Source field.

  2. The Create Source window expands with additional fields. The Credential is required. Choose from an existing credential (for more information, refer to Credentials).

Inventories - create source - RHV example

15.3.4.1.10. Ansible Tower
  1. To configure a Ansible Tower-sourced inventory, select Ansible Tower from the Source field.

  2. The Create Source window expands with additional fields. Enter the following details:

  • Credential: Required. Choose from an existing credential (for more information, refer to Credentials).

  • Instance Filters: Rather than importing your entire Tower inventory, filter the instances by an inventory ID/name; then the inventory script would return that inventory from the other Tower instance.

_images/inventories-create-source-atower-example.png
15.3.4.1.11. Custom Script

Tower allows you to use a custom dynamic inventory script, if your administrator has added one.

  1. To configure a Custom Script-sourced inventory, select Custom Script from the Source field.

  2. The Create Source window expands with additional fields. Enter the following details:

  • Credential: You can optionally provide a credential for custom sources. The kind of credential is limited to cloud and network. Refer to Custom Credential Types for more information.

  • Custom Inventory Script: Required. Choose from an existing Inventory Script (for more information, refer to Custom Inventory Scripts).

  • Environment Variables: Set variables in the environment to be used by the inventory update script. The variables would be specific to the script that you have written. Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.

Inventories - create source - custom script example

For more information on syncing or using custom inventory scripts, refer to Custom Inventory Scripts in the Ansible Tower Administration Guide.

15.3.5. View completed jobs

If an inventory was used to run a job, you can view details about those jobs in the Completed Jobs tab of the inventory and click Expanded to view details about each job.

Inventories view completed jobs

15.3.5.1. Smart Host Filter

You can use a search filter to populate hosts for an inventory. This feature was introduced in Ansible Tower 3.2 utilizing the capability of the fact searching feature.

Facts generated by an Ansible playbook during a Job Template run are stored by Tower into the database whenever use_fact_cache=True is set per-Job Template. New facts are merged with existing facts and are per-host. These stored facts can be used to filter hosts via the /api/v2/hosts endpoint, using the GET query parameter host_filter For example: /api/v2/hosts?host_filter=ansible_facts__ansible_processor_vcpus=8

The host_filter parameter allows for:

  • grouping via ()

  • use of the boolean and operator:

    • __ to reference related fields in relational fields

    • __ is used on ansible_facts to separate keys in a JSON key path

    • [] is used to denote a json array in the path specification

    • "" can be used in the value when spaces are wanted in the value

  • “classic” Django queries may be embedded in the host_filter

Examples:

/api/v2/hosts/?host_filter=name=localhost
/api/v2/hosts/?host_filter=ansible_facts__ansible_date_time__weekday_number="3"
/api/v2/hosts/?host_filter=ansible_facts__ansible_processor[]="GenuineIntel"
/api/v2/hosts/?host_filter=ansible_facts__ansible_lo__ipv6[]__scope="host"
/api/v2/hosts/?host_filter=ansible_facts__ansible_processor_vcpus=8
/api/v2/hosts/?host_filter=ansible_facts__ansible_env__PYTHONUNBUFFERED="true"
/api/v2/hosts/?host_filter=(name=localhost or name=database) and (groups__name=east or groups__name="west coast") and ansible_facts__an

You can search host_filter by host name, group name, and Ansible facts.

The format for a group search is:

groups.name:groupA

The format for a fact search is:

ansible_facts.ansible_fips:false

You can also perform Smart Search searches, which consist a host name and host description.

host_filter=name=my_host

If a search term in host_filter is of string type, to make the value a number (e.g. 2.66), or a JSON keyword (e.g. null, true or false) valid, add double quotations around the value to prevent Tower from mistakenly parsing it as a non-string:

host_filter=ansible_facts__packages__dnsmasq[]__version="2.66"

15.4. Running Ad Hoc Commands

To run an ad hoc command:

  1. Select an inventory source from the list of hosts or groups. The inventory source can be a single group or host, a selection of multiple hosts, or a selection of multiple groups.

ad hoc-commands-inventory-home

  1. Click the adhoc button.

The Execute Command window opens.

_images/ad-hoc-run-execute-command.png
  1. Enter the details for the following fields:

  • Module: Select one of the modules that Tower supports running commands against.

    command

    apt_repository

    mount

    win_service

    shell

    apt_rpm

    ping

    win_updates

    yum

    service

    selinux

    win_group

    apt

    group

    setup

    win_user

    apt_key

    user

    win_ping

  • Arguments: Provide arguments to be used with the module you selected.

  • Limit: Enter the limit used to target hosts in the inventory. To target all hosts in the inventory enter all or *, or leave the field blank. This is automatically populated with whatever was selected in the previous view prior to clicking the launch button.

  • Machine Credential: Select the credential to use when accessing the remote hosts to run the command. Choose the credential containing the username and SSH key or password that Ansbile needs to log into the remote hosts.

  • Verbosity: Select a verbosity level for the standard output.

  • Forks: If needed, select the number of parallel or simultaneous processes to use while executing the command.

  • Show Changes: Select to enable the display of Ansible changes in the standard output. The default is OFF.

  • Enable Privilege Escalation: If enabled, the playbook is run with administrator privileges. This is the equivalent of passing the --become option to the ansible command.

  • Extra Variables: Provide extra command line variables to be applied when running this inventory. Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.

ad hoc-commands-inventory-run-command

  1. Click the launch-adhoc button to run this ad hoc command.

The results display in the Details pane and Standard Out window.

ad hoc-commands-inventory-results-example