HomeGuidesAPI ReferenceGuidesMRT APIConfiguration API
GitHubAirheads Developer Community
Guides

Building a Dynamic Inventory

📘

Source Code

You can find this inventory file in the collection repository: examples/central_inventory.yml

This example configures the central_inventory dynamic inventory plugin to discover every device in a New Central account and group it by site, device type, model, status, and device group — instead of maintaining a static inventory file by hand.

Prerequisites

  • A New Central account with API access enabled
  • A client_id and client_secret (or a pre-generated access_token) for New Central

Installation

  1. Install the collection from Ansible Galaxy:
ansible-galaxy collection install arubanetworks.hpeanw_central
  1. Install the pycentral v2 SDK, which the collection depends on:
pip3 install --pre pycentral

This workflow is tested on collection version 2.1.1-beta. Please check compatibility before executing on older/newer versions as there may be changes.

Configuration

Unlike the other workflows, credentials for this plugin are provided directly inside the inventory file itself (or via environment variables), rather than through a separate inventory.yml variables file.

# central_inventory.yml
plugin: arubanetworks.hpeanw_central.central_inventory

# Authentication (choose one method)
central_base_url: <central-api-base-url>
central_client_id: <new-central-client-id>          # Method 1: OAuth credentials
central_client_secret: <new-central-client-secret>
# central_access_token: <new-central-access-token>   # Method 2: Direct token

# Or set these as environment variables instead:
# export ARUBA_CENTRAL_BASE_URL="https://us5.api.central.arubanetworks.com"
# export ARUBA_CENTRAL_CLIENT_ID="<new-central-client-id>"
# export ARUBA_CENTRAL_CLIENT_SECRET="<new-central-client-secret>"

# Which groups to build (default: site, device_type)
groups:
  - site
  - device_type
  - model
  - status
  - group

# Optional: filter which devices are discovered
# filters:
#   device_type:
#     - ACCESS_POINT
#     - SWITCH
#   status:
#     - ONLINE

# Optional: write the discovered inventory to a file. The access token is
# cached here too, so subsequent runs reuse it instead of generating a new one.
output_file: ./central_devices_inventory.yml
📘

Important Links

Execution

List the discovered inventory:

ansible-inventory -i central_inventory.yml --list

Run a playbook against it:

ansible-playbook playbook.yml -i central_inventory.yml

Target a generated group, such as all switches or a specific site:

ansible-playbook configure_switches.yml -i central_inventory.yml --limit type_switch
ansible-playbook deploy.yml -i central_inventory.yml --limit site_building_a

Playbooks can also reference the credentials the plugin stored at the all group level:

- name: Call Central API
  arubanetworks.hpeanw_central.central_api:
    base_url: "{{ central_base_url }}"
    access_token: "{{ central_access_token }}"
    method: GET
    path: "/monitoring/v2/devices"

Output

The plugin builds a hierarchical inventory: all.vars holds the shared Central credentials, all.hosts holds one entry per device (keyed by serial number) with metadata like status, deviceType, model, siteName, softwareVersion, and isProvisioned, and all.children holds the generated groups (site_*, type_*, model_*, status_*, group_*). If output_file is set, this structure — including the current access token — is written to disk and reused on the next run.

Troubleshooting

ProblemFix
Authentication failuresVerify central_base_url matches your account's region and that central_client_id/central_client_secret (or central_access_token) are valid
Empty inventoryCheck filters — an overly narrow filter can exclude every device
Stale device dataIf output_file is set, the plugin reuses the cached token/data — delete the file to force a full refresh

Support


Did this page help you?