MSP Automation
The msp_token module generates OAuth tokens for Managed Service Provider (MSP) workflows: a workspace-level token for MSP-level operations, and — when a tenant is specified — a tenant-scoped token exchanged from it. This lets a playbook call Central and GLP APIs at the MSP workspace level or scoped to an individual managed tenant, without writing the token exchange flow by hand.
Manual Token Exchange
msp_tokenautomates the flow described in MSP Token Exchange: generate an MSP access token, then exchange it for a tenant workspace token. If you need to understand what's happening under the hood, or you're not using Ansible, that guide walks through the same steps as raw API calls.
Prerequisites
- GLP Client ID & Client Secret — Credentials for the MSP workspace, created at the GreenLake Platform level (not scoped to a single Central instance). See Creating an API Credential.
- MSP Workspace ID — Find it by logging in to common.cloud.hpe.com, navigating to Manage Workspace, and copying the Workspace ID.
- Tenant ID or Tenant Name (for tenant-scoped operations) — Either identifies the tenant to exchange a token for.
tenant_idaccepts a UUID with or without dashes — the module normalizes it for you before the exchange, so you don't need to strip hyphens manually the way a raw API call requires.
Security NoteAlways use
no_log: trueonmsp_tokentasks. Storeclient_id/client_secretin Ansible Vault or environment variables rather than plain text.
How This Differs From PyCentral's MSPBase
MSPBaseIf you've used PyCentral's MSPBase class, note one key difference: MSPBase is a long-lived Python session object that caches its MSP token and each tenant connection, reusing them across calls and refreshing automatically on expiry.
The msp_token module has no equivalent session to hold open between tasks. Every call to msp_token — workspace-level or tenant-scoped — independently authenticates with your client_id/client_secret and performs its own token (or token exchange) request. There's no connection cache: if you need a tenant's token again later in the same play, call msp_token again for that tenant rather than trying to reuse a variable from an earlier task, since MSP and tenant tokens expire in 15 minutes.
MSP-Level Operations
Generate a workspace-level token by omitting tenant_id/tenant_name, then use msp_access_token with the generic central_api/glp_api modules for MSP-level calls — listing tenants, MSP-wide inventory, or subscription data.
- name: MSP-level operations
hosts: localhost
gather_facts: no
tasks:
- name: Generate MSP workspace-level token
arubanetworks.hpeanw_central.msp_token:
client_id: "{{ msp_client_id }}"
client_secret: "{{ msp_client_secret }}"
msp_workspace_id: "{{ msp_workspace_id }}"
register: msp_token_result
no_log: true
- name: List tenants from Central
arubanetworks.hpeanw_central.central_api:
base_url: "{{ central_base_url }}"
access_token: "{{ msp_token_result['msp_access_token'] }}"
method: GET
path: "/network-msp/v1/list-tenants"
params:
limit: 100
register: central_tenants_result
- name: List devices from GLP
arubanetworks.hpeanw_central.glp_api:
access_token: "{{ msp_token_result['msp_access_token'] }}"
method: GET
path: "/devices/v1/devices"
register: glp_devices_resultTenant-Scoped Operations
Provide tenant_id or tenant_name to msp_token to get a token exchanged for that tenant's workspace. Use tenant_access_token the same way you'd use any other access_token — it's scoped exclusively to that tenant's data.
- name: Tenant-scoped operations
hosts: localhost
gather_facts: no
tasks:
- name: Generate a tenant-scoped token by tenant name
arubanetworks.hpeanw_central.msp_token:
client_id: "{{ msp_client_id }}"
client_secret: "{{ msp_client_secret }}"
msp_workspace_id: "{{ msp_workspace_id }}"
tenant_name: "Example Tenant Name"
register: tenant_token_result
no_log: true
- name: Get devices in the tenant's Central instance
arubanetworks.hpeanw_central.central_api:
base_url: "{{ central_base_url }}"
access_token: "{{ tenant_token_result['tenant_access_token'] }}"
method: GET
path: "/network-monitoring/v1alpha1/devices"
register: tenant_devices_result
- name: Get audit logs from the tenant's GLP workspace
arubanetworks.hpeanw_central.glp_api:
access_token: "{{ tenant_token_result['tenant_access_token'] }}"
method: GET
path: "/audit-log/v1/logs"
register: tenant_audit_resultIterating Across Tenants
The most common MSP automation pattern: fetch the tenant list once, then run a tenant-scoped operation for each one. Because there's no cached session to reuse, generate a token per tenant inside the loop.
- name: Run an operation across every managed tenant
hosts: localhost
gather_facts: no
tasks:
- name: Generate MSP workspace-level token
arubanetworks.hpeanw_central.msp_token:
client_id: "{{ msp_client_id }}"
client_secret: "{{ msp_client_secret }}"
msp_workspace_id: "{{ msp_workspace_id }}"
register: msp_token_result
no_log: true
- name: List managed tenants
arubanetworks.hpeanw_central.glp_api:
access_token: "{{ msp_token_result['msp_access_token'] }}"
method: GET
path: "/workspaces/v1/msp-tenants"
register: tenants_result
- name: Generate a tenant-scoped token for each tenant
arubanetworks.hpeanw_central.msp_token:
client_id: "{{ msp_client_id }}"
client_secret: "{{ msp_client_secret }}"
msp_workspace_id: "{{ msp_workspace_id }}"
tenant_id: "{{ item.id }}"
loop: "{{ tenants_result.result.msg.items }}"
loop_control:
label: "{{ item.workspaceName }}"
register: tenant_tokens
no_log: true
- name: Get devices for each tenant
arubanetworks.hpeanw_central.central_api:
base_url: "{{ central_base_url }}"
access_token: "{{ item.tenant_access_token }}"
method: GET
path: "/network-monitoring/v1alpha1/devices"
loop: "{{ tenant_tokens.results }}"
loop_control:
label: "{{ item.item.workspaceName }}"
register: tenant_devices
TipWhen a task with
loopalso usesregister, Ansible stores one result per iteration under.results, and each entry carries both the loop variable (.item) and that task's own output fields (liketenant_access_token) merged in. The second loop above readsitem.tenant_access_tokendirectly anditem.item.workspaceNamefor the original tenant record.
Troubleshooting
| Problem | Fix |
|---|---|
| 401 on MSP token generation | Verify client_id/client_secret are valid and were created at the GreenLake Platform level, not scoped to a single Central instance |
| 403 on a tenant-scoped API call | Confirm you used tenant_access_token (not msp_access_token) and that tenant_id/tenant_name matches an actual managed tenant |
| Tenant token calls fail partway through a long loop | MSP and tenant tokens expire in 15 minutes — for very large tenant lists, split the loop into batches or re-run msp_token closer to when each tenant's token is used |
Support
- Automation Team: [email protected]
- Collection Issues: GitHub Issues
Updated 4 months ago