HomeGuidesAPI ReferenceGuidesMRT APIConfiguration API
GitHubAirheads Developer Community
Guides

Central API Demo

📘

Source Code

You 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_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

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_result

Run it with:

ansible-playbook -i inventory.yml central_api_demo.yml

Module Parameters

ParameterTypeRequiredDescription
base_urlstrYesNew Central base URL
client_id/client_secretstrNo*Used to auto-generate a token; omit if providing access_token
access_tokenstrNo*Pre-generated OAuth token; omit if providing client_id/client_secret
methodstrNoHTTP method (GET, POST, PUT, DELETE, PATCH); default GET
pathstrYesAPI endpoint path, without the base URL
datadictNoRequest body for POST/PUT/PATCH
paramsdictNoURL query parameters

* One of access_token or client_id+client_secret is required.

Output

The sites_result variable registered from the task contains:

FieldDescription
codeHTTP response status code
msgResponse body (dict or string, depending on the API)
headersResponse headers

Troubleshooting

ProblemFix
401/403 responseVerify client_id/client_secret are valid and have API access enabled
404 responseConfirm path matches a valid New Central endpoint and API version
Wrong region errorsConfirm base_url matches the API Gateway for your Central cluster's region

Support


Did this page help you?