HomeGuidesAPI ReferenceGuidesMRT APIConfiguration API
GitHubAirheads Developer Community
Guides

Configuring Local AOS-CX Switch Profiles

📘

Source Code

You can find these playbooks in the collection repository: examples/central_cx_local_profiles.yml and examples/undo_central_cx_local_profiles.yml

This pair of playbooks configures — and then reverses — local (device-scoped) profiles on a single AOS-CX switch: a library VLAN assigned to the switch's site scope, per-interface access VLANs, and a custom login banner.

Prerequisites

  • A New Central account with API access enabled
  • A client_id and client_secret for New Central
  • An AOS-CX switch already provisioned in Central, with its site scope ID and device scope ID known

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

Playbook Variables

Edit the vars block at the top of the playbook before running it:

VariableDescription
site_scope_idScope ID of the switch's site in Central
switch_serialSerial number of the AOS-CX switch
switch_scope_idDevice scope ID of the AOS-CX switch
switch_personaPersona of the switch (e.g., ACCESS_SWITCH)
interfacesList of {interface, access_vlan} pairs to configure

Execution

Apply

- name: Configure Local L2 interfaces & Banner on AOS-CX Switch
  hosts: localhost
  vars:
    site_scope_id: 37104267151
    switch_serial: AAABBBCCCDD
    switch_scope_id: 46505163378
    switch_persona: ACCESS_SWITCH
    interfaces:
      - interface: 1/1/14
        access_vlan: 100
      - interface: 1/1/15
        access_vlan: 100
      - interface: 1/1/16
        access_vlan: 100
  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

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

    - name: Create Library Vlan Config Profile
      arubanetworks.hpeanw_central.central_profiles:
        base_url: "{{ central_base_url }}"
        access_token: "{{ central_access_token }}"
        path: "layer2-vlan"
        name: 100
        state: merged
        config_dict:
          vlan: 100
          enable: True
          name: Ansible-VLAN

    - name: Assign Library Profile to Scope
      arubanetworks.hpeanw_central.central_api:
        base_url: "{{ central_base_url }}"
        access_token: "{{ central_access_token }}"
        method: POST
        path: "/network-config/v1alpha1/scope-maps"
        data:
          scope-map:
            - scope-name: "{{ site_scope_id }}"
              persona: "{{ switch_persona }}"
              resource: "layer2-vlan/100"

    - name: Update local L2 interfaces Device scope
      arubanetworks.hpeanw_central.central_profiles:
        base_url: "{{ central_base_url }}"
        access_token: "{{ central_access_token }}"
        name: "{{ item.interface }}"
        path: "ethernet-interfaces"
        resource: "ethernet-interfaces"
        state: merged
        local:
          scope_id: "{{ switch_scope_id }}"
          persona: "{{ switch_persona }}"
        config_dict:
          poe:
            enabled: True
          enable: true
          routing: false
          switchport:
            interface-mode: ACCESS
            access-vlan: "{{ item.access_vlan }}"
      loop: "{{ interfaces }}"

    - name: Create a local Banner Device scope
      arubanetworks.hpeanw_central.central_profiles:
        base_url: "{{ central_base_url }}"
        access_token: "{{ central_access_token }}"
        name: profile-{{ switch_serial }}
        path: local-management
        resource: local-management
        state: merged
        local:
          scope_id: "{{ switch_scope_id }}"
          persona: "{{ switch_persona }}"
        config_dict:
          name: profile-{{ switch_serial }}
          webservers:
            enabled-vrfs:
              - default
              - mgmt
          ssh-server-global-configs:
            enabled-vrfs:
              - default
              - mgmt
          banner-message:
            message-delimiter: "~"
            text: |
              !
              WARNING - Unauthorized access to this device is strictly prohibited - WARNING
              !

Run it with:

ansible-playbook -i inventory.yml central_cx_local_profiles.yml

Rollback

The undo_central_cx_local_profiles.yml playbook reverses each step in order: it clears the banner (setting banner-message to null), resets the interfaces to VLAN 1, unassigns the library VLAN from the site scope, then deletes the library VLAN profile. Use the same site_scope_id, switch_serial, switch_scope_id, and switch_persona values as the apply playbook.

ansible-playbook -i inventory.yml undo_central_cx_local_profiles.yml
👍

Tip

Setting a config_dict key to null (as the rollback playbook does for banner-message) removes that value from the profile rather than setting it to an empty value.

Output

Each central_profiles and central_api task reports:

FieldDescription
changedtrue if the profile or scope assignment was created, modified, or deleted
msgSuccess message, or error details if the operation failed
resultResponse details; includes a diff of old_value/new_value when state: merged causes an update

Troubleshooting

ProblemFix
Scope-map assignment failsConfirm site_scope_id and switch_persona match the switch's actual site and persona in Central
Interface not foundConfirm switch_scope_id is the device scope ID (not the site scope ID) and the interface name matches the switch's port naming
Rollback leaves VLAN in useEnsure no interfaces still reference the VLAN before deleting the library profile — the rollback playbook resets interfaces before deleting the profile for this reason

Support


Did this page help you?