Central API Demo
Source CodeYou can find this playbook in the collection repository:
examples/central_api_demo.yml
This playbook demonstrates calling the New Central REST API directly with the central_api module, without a purpose-built module wrapping the endpoint. It's the fastest way to explore an endpoint or reach one the collection doesn't yet have a dedicated module for.
Prerequisites
- A New Central account with API access enabled
- A
client_idandclient_secret(or a pre-generatedaccess_token) for New Central
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)
For API operations in HPE Aruba Networking Central:
all:
hosts:
localhost:
ansible_connection: local # Do not change
central_base_url: <central-api-base-url>
central_client_id: <new-central-client-id>
central_client_secret: <new-central-client-secret>
Important Links
Execution
The central_api module accepts client_id/client_secret directly — when no access_token is supplied, it generates one for you, so no separate token-generation task is required:
- name: Demo HPE Aruba Networking Central API Calls
hosts: localhost
gather_facts: no
tasks:
- name: Get Sites from Central
arubanetworks.hpeanw_central.central_api:
base_url: "{{ central_base_url }}"
client_id: "{{ central_client_id }}"
client_secret: "{{ central_client_secret }}"
method: GET
path: "/network-config/v1/sites"
register: sites_result
- debug:
var: sites_resultRun it with:
ansible-playbook -i inventory.yml central_api_demo.ymlModule Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
base_url | str | Yes | New Central base URL |
client_id/client_secret | str | No* | Used to auto-generate a token; omit if providing access_token |
access_token | str | No* | Pre-generated OAuth token; omit if providing client_id/client_secret |
method | str | No | HTTP method (GET, POST, PUT, DELETE, PATCH); default GET |
path | str | Yes | API endpoint path, without the base URL |
data | dict | No | Request body for POST/PUT/PATCH |
params | dict | No | URL query parameters |
* One of access_token or client_id+client_secret is required.
Output
The sites_result variable registered from the task contains:
| Field | Description |
|---|---|
code | HTTP response status code |
msg | Response body (dict or string, depending on the API) |
headers | Response headers |
Troubleshooting
| Problem | Fix |
|---|---|
| 401/403 response | Verify client_id/client_secret are valid and have API access enabled |
| 404 response | Confirm path matches a valid New Central endpoint and API version |
| Wrong region errors | Confirm base_url matches the API Gateway for your Central cluster's region |
Support
- Automation Team: [email protected]
- Collection Issues: GitHub Issues
Updated 4 months ago