HomeGuidesAPI ReferenceGuidesMRT APIConfiguration API
GitHubAirheads Developer Community
Guides

Creating Sites and Assigning Devices

📘

Source Code

You can find this playbook in the collection repository: examples/central_sites.yml

This playbook creates a site in New Central, then assigns devices to that site using the Classic Central API. Site creation happens through New Central's central_sites module; device-to-site assignment currently happens through classic_sites.

Prerequisites

  • A New Central account and a Classic Central account with API access enabled
  • A client_id and client_secret for New Central
  • A pre-generated access_token for Classic Central
  • Device serial numbers for the devices you want to assign to the site

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(Advanced)

Credentials Configuration (inventory.yml)

all:
  hosts:
    localhost:
      ansible_connection: local # Do not change
      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

Execution

- name: Create Sites and Assign Devices in HPE Aruba Networking Central
  hosts: localhost
  gather_facts: no
  tasks:
    - name: Create OAuth Token from Central
      arubanetworks.hpeanw_central.central_token:
        base_url: "{{ central_base_url }}"
        client_id: "{{ central_client_id }}"
        client_secret: "{{ central_client_secret }}"
      register: token_result
      no_log: true

    - set_fact:
        central_access_token: "{{ token_result['access_token'] }}"
      no_log: true

    - name: Create a new Site
      arubanetworks.hpeanw_central.central_sites:
        base_url: "{{ central_base_url }}"
        access_token: "{{ central_access_token }}"
        site_attributes:
          name: Ansible Campus
          address: "123 S St"
          city: "Sacramento"
          state: "California"
          country: "United States"
          zipcode: "12345"
          timezone: "America/Los_Angeles"
        state: merged

    - name: Assign Devices to Sites Using Classic HPE Aruba Networking Central API
      arubanetworks.hpeanw_central.classic_sites:
        base_url: "{{ classic_base_url }}"
        access_token: "{{ classic_access_token }}"
        site_name: "Ansible Campus"
        device_type: "ACCESS_POINT"
        devices:
          - "AABBCCDD11"
          - "DDCCBBAA22"
        state: assigned
      register: sites_result

Run it with:

ansible-playbook -i inventory.yml central_sites.yml

Module Parameters

central_sites — site_attributes requires name, address, city, state, country, zipcode, and timezone. state is merged (default) or deleted.

classic_sites — devices must all be the same device_type (ACCESS_POINT, SWITCH, or GATEWAY). state is assigned (default) or unassigned.

Output

central_sites reports changed, a msg describing the result, and a result boolean or detail dictionary on failure. classic_sites (registered as sites_result) reports the underlying API result, including code, msg, and headers.

Troubleshooting

ProblemFix
Site creation failsConfirm all required site_attributes fields are present and state/country use their ISO short names
Device assignment failsConfirm the devices are already provisioned in Central and all listed devices share the same device_type
Site exists but devices don't moveclassic_sites only assigns devices — re-run central_sites first if the site itself needs updates

Support


Did this page help you?