Querying GLP Device Inventory
Source CodeYou can find these playbooks in the collection repository:
examples/glp_api.ymlandexamples/glp_devices_info.yml
These playbooks retrieve device inventory data from GLP with glp_devices_info — from a simple "get everything" query to filtered, field-selected lookups by serial number, filter expression, or device ID.
Prerequisites
- A GLP workspace with API access enabled
- A
client_idandclient_secretfor GLP
Installation
- Install the collection from Ansible Galaxy:
ansible-galaxy collection install arubanetworks.hpeanw_central- Install the
pycentralv2 SDK, which the collection depends on:
pip3 install --pre pycentralThis 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
Credentials Configuration (inventory.yml)
all:
hosts:
localhost:
ansible_connection: local # Do not change
glp_client_id: <glp-client-id>
glp_client_secret: <glp-client-secret>
Important Links
Execution
Quick Start
Generate a token and retrieve the full device inventory:
- name: Demo HPE GreenLake Platform Devices Info
hosts: localhost
gather_facts: no
tasks:
- name: Generate Token for Session
arubanetworks.hpeanw_central.glp_token:
client_id: "{{ glp_client_id }}"
client_secret: "{{ glp_client_secret }}"
register: token_result
no_log: true
- name: Retrieve Devices from GLP
arubanetworks.hpeanw_central.glp_devices_info:
access_token: "{{ token_result['access_token'] }}"
register: glp_device_inventory
- debug:
var: glp_device_inventoryansible-playbook -i inventory.yml glp_api.ymlFiltering and Selecting Fields
glp_devices_info supports four subset modes and an optional select field list, all using the same generated token:
- name: Get SERIAL in GLP with Token
arubanetworks.hpeanw_central.glp_devices_info:
access_token: "{{ token_result['access_token'] }}"
subset: device_by_serial
serial_number: "ABC123456"
register: devices_result
- name: Get Select MAC from All Devices in GLP with Token
arubanetworks.hpeanw_central.glp_devices_info:
access_token: "{{ token_result['access_token'] }}"
select: "macAddress"
register: devices_result
- name: Get device by filter
arubanetworks.hpeanw_central.glp_devices_info:
access_token: "{{ token_result['access_token'] }}"
subset: device_by_filter
device_filter: "serialNumber eq 'ABC123456'"
register: devices_result
- name: Get device by ID
arubanetworks.hpeanw_central.glp_devices_info:
access_token: "{{ token_result['access_token'] }}"
subset: device_by_id
device_id: 111222333-444555-666777888-999000
register: devices_resultansible-playbook -i inventory.yml glp_devices_info.ymlModule Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
subset | str | No | all_devices (default), device_by_filter, device_by_id, or device_by_serial |
device_filter | str | With device_by_filter | Filter expression, e.g. serialNumber eq 'ABC123456' |
device_id | str | With device_by_id | Device ID to retrieve |
serial_number | str | With device_by_serial | Device serial number to look up |
select | str | No | Comma-separated list of fields to return, e.g. id,serialNumber,model,macAddress |
Output
Each task registers a result containing devices (a list of device dictionaries scoped to the requested subset/select), the HTTP code, and a msg.
Troubleshooting
| Problem | Fix |
|---|---|
Empty devices list | Verify the device_filter/serial_number/device_id matches an existing device |
| Filter syntax errors | device_filter uses OData-style expressions, e.g. field eq 'value' |
| Missing fields in response | Confirm select includes the field names you expect, exactly as GLP returns them |
Support
- Automation Team: [email protected]
- Collection Issues: GitHub Issues
Updated 4 months ago