Creating and Assigning Device Groups
Source CodeYou can find this playbook in the collection repository:
examples/classic_groups.yml
This playbook creates Classic Central device groups — with their template and architecture properties — and assigns devices to them in the same task.
Prerequisites
- A Classic Central account with API access enabled
- A pre-generated Classic Central
access_token - Device serial numbers for the devices you want to assign to a group
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
classic_base_url: <classic-central-api-base-url>
classic_access_token: <classic-central-access-token>
Important Links
Execution
- name: Create Sites in HPE Aruba Networking Central
hosts: localhost
gather_facts: no
tasks:
- name: Assign Devices to Sites in Classic HPE Aruba Networking Central
arubanetworks.hpeanw_central.classic_groups:
base_url: "{{ classic_base_url }}"
access_token: "{{ classic_access_token }}"
group_name: "Ansible-Device-Group-1"
group_attributes:
template_info:
Wired: false
group_properties:
AllowedDevTypes:
- AccessPoints
- Gateways
- Switches
Architecture: AOS10
ApNetworkRole: Standard
GwNetworkRole: BranchGateway
AllowedSwitchTypes:
- AOS_CX
NewCentral: true
device_type: "ACCESS_POINT"
devices:
- "PHQSL1N5HB"
- "PHQSL1N56K"
state: merged
register: sites_result
- name: Create a device group for Switches
arubanetworks.hpeanw_central.classic_groups:
base_url: "{{ classic_base_url }}"
access_token: "{{ classic_access_token }}"
group_name: "Fabric2-Switches"
group_attributes:
template_info:
Wired: false
group_properties:
AllowedDevTypes:
- Switches
AllowedSwitchTypes:
- AOS_CX
NewCentral: true
device_type: "SWITCH"
devices: []
state: mergedRun it with:
ansible-playbook -i inventory.yml classic_groups.ymlModule Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
group_name | str | Yes | Name of the device group |
group_attributes | dict | When state: merged | Group template/properties to create or update the group with |
device_type | str | Yes | ACCESS_POINT, SWITCH, or GATEWAY — all devices must be this type |
devices | list | Yes | Serial numbers to assign or unassign; pass [] to create a group without assigning devices |
state | str | No | merged (create/update group), deleted (delete group), assigned (default), or unassigned |
Output
Each task reports result, containing the HTTP code, response msg, and headers from the underlying API call.
Troubleshooting
| Problem | Fix |
|---|---|
| Group creation fails | Check group_attributes.group_properties.AllowedDevTypes/AllowedSwitchTypes are valid for your architecture |
| Device assignment fails | Confirm all devices share the same device_type and are already provisioned in Central |
| Deleting a group with devices | state: deleted moves devices to the default group rather than failing — confirm that's the intended outcome |
Support
- Automation Team: [email protected]
- Collection Issues: GitHub Issues
Updated 4 months ago
Did this page help you?