Bulk Onboarding Devices from GLP Inventory
Source CodeYou can find this playbook in the collection repository:
examples/onboarding_advanced_example.yml
This playbook onboards devices that are already registered in GLP inventory. Rather than listing each device's application and subscription by hand, it fetches the full GLP device inventory, filters it down to a list of target serial numbers, builds a lookup table mapping each device's part number to its application and subscription, and then loops through onboarding into Central — creating the site, assigning devices, creating device-type-specific groups, and assigning personas dynamically based on each device's type.
Proof of ConceptThis playbook is for demonstrating dynamic, data-driven onboarding at scale. It is not optimized for production migrations — review the persona/device-type mapping logic against your own device types before running it broadly.
Prerequisites
- A GreenLake workspace, New Central account, and Classic Central account with API access enabled
- Devices already present in GLP inventory, each with a
partNumber,application, andsubscriptionalready resolvable in GLP - The serial numbers of the devices to onboard from that inventory
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(Advanced)
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>
central_base_url: <new-central-api-base-url>
central_client_id: <new-central-client-id>
central_client_secret: <new-central-client-secret>
classic_base_url: <classic-central-api-base-url>
classic_access_token: <classic-central-access-token>
Important Links
Playbook Variables
| Variable | Description |
|---|---|
site_name | Name of the site to create in Central |
group_name | Prefix used to build a per-device-type group name (e.g. Ansible- + SWITCH) |
application_region | GLP application region — see the region reference |
onboard_list | Serial numbers to select out of the full GLP inventory for onboarding |
Execution
The playbook fetches every device from GLP, then uses set_fact and when conditions to build the working device list and application/subscription mapping before touching Central:
- name: Onboard Devices into HPE Aruba Networking Central
hosts: localhost
gather_facts: no
vars:
site_name: "Ansible-Campus"
group_name: "Ansible-"
application_region: "us-west"
onboard_list:
- TW3BLZBBBQ
- TW3BLZBBBB
- CNSKKLBBB8
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
- name: Build Onboard Device List
set_fact:
onboard_devices: "{{ onboard_devices | default([]) + [item] }}"
loop: "{{ glp_device_inventory.devices }}"
when: item.serialNumber in onboard_list
- name: Create mapping of device part numbers to applications and subscriptions
set_fact:
device_part_mapping: "{{ device_part_mapping | default({}) | combine({item.partNumber: {'application': item.application, 'subscription': item.subscription[0]}}) }}"
loop: "{{ glp_device_inventory.devices }}"
when: item.subscription != None and item.subscription | length > 0 and item.application != None
- name: Assign Devices to GLP & Assign subscriptions
arubanetworks.hpeanw_central.glp_devices:
access_token: "{{ token_result['access_token'] }}"
application:
id: "{{ device_part_mapping[item.partNumber].application.id }}"
region: "{{ application_region }}"
subscription_key: "{{ device_part_mapping[item.partNumber].subscription.key }}"
devices:
- "{{ item.serialNumber }}"
state: "assigned"
loop: "{{ onboard_devices }}"
when: onboard_devices is defined and onboard_devices | length > 0
- name: Create Site Ansible_Site in Central
arubanetworks.hpeanw_central.central_sites:
base_url: "{{ central_base_url }}"
access_token: "{{ central_access_token }}"
site_attributes:
name: "{{ site_name }}"
address: "123 Main St"
city: "San Jose"
state: "California"
country: "United States"
zipcode: "12345"
timezone: "America/Los_Angeles"
state: merged
- name: Assign Devices to Sites in Classic HPE Aruba Networking Central
arubanetworks.hpeanw_central.classic_sites:
base_url: "{{ classic_base_url }}"
access_token: "{{ classic_access_token }}"
site_name: "{{ site_name }}"
device_type: "{{ item.deviceType }}"
devices:
- "{{ item.serialNumber }}"
state: assigned
loop: "{{ onboard_devices }}"
when: onboard_devices is defined and onboard_devices | length > 0
ignore_errors: yes
- name: Create Group and Assign Devices to Group for Configuration in HPE Aruba Networking Central
arubanetworks.hpeanw_central.classic_groups:
base_url: "{{ classic_base_url }}"
access_token: "{{ classic_access_token }}"
group_name: "{{ group_name }}{{ item.deviceType }}"
group_attributes:
template_info:
Wired: false
group_properties:
AllowedDevTypes:
- AccessPoints
- Gateways
- Switches
Architecture: AOS10
ApNetworkRole: Standard
GwNetworkRole: WLANGateway
AllowedSwitchTypes:
- AOS_CX
NewCentral: true
device_type: "{{ item.deviceType }}"
devices:
- "{{ item.serialNumber }}"
state: merged
when: onboard_devices is defined and onboard_devices | length > 0
loop: "{{ onboard_devices }}"
ignore_errors: yes
- name: Assign Device Functions/Personas in HPE Aruba Networking Central
arubanetworks.hpeanw_central.central_api:
base_url: "{{ central_base_url }}"
access_token: "{{ central_access_token }}"
method: POST
path: "/network-config/v1alpha1/persona-assignment/{{ 'ACCESS_SWITCH' if item.deviceType == 'SWITCH' else ('CAMPUS_AP' if item.deviceType == 'ACCESS_POINT' else 'MOBILITY_GW') }}"
data:
persona-device-list:
- device-function: "{{ 'ACCESS_SWITCH' if item.deviceType == 'SWITCH' else ('CAMPUS_AP' if item.deviceType == 'ACCESS_POINT' else 'MOBILITY_GW') }}"
device-id:
- "{{ item.serialNumber }}"
when: onboard_devices is defined and onboard_devices | length > 0
loop: "{{ onboard_devices }}"
ignore_errors: yesRun it with:
ansible-playbook -i inventory.yml onboarding_advanced_example.yml
Tip
ignore_errors: yeson the site/group/persona steps means one device's failure won't stop the rest of the batch from onboarding. Review the play recap for anyfailedtasks after the run completes.
Output
There is no single consolidated result — the play recap at the end of the run shows ok/changed/failed/ignored counts per task. Because several tasks use ignore_errors, check each task's per-item output (or add debug tasks on the registered variables) to confirm every device in onboard_devices actually succeeded, not just that the play finished.
Troubleshooting
| Problem | Fix |
|---|---|
onboard_devices ends up empty | No device in GLP inventory matched onboard_list — confirm the serial numbers exist in GLP |
device_part_mapping missing a part number | The matched device has no application/subscription in GLP yet — assign it manually first, or via Assigning Devices to Applications and Subscriptions in GLP |
| Persona assignment picks the wrong function | The device-function expression only maps SWITCH/ACCESS_POINT/anything else (treated as MOBILITY_GW) — extend it if you have other device types |
Support
- Automation Team: [email protected]
- Collection Issues: GitHub Issues
Updated 4 months ago