graphiant.naas.graphiant_macsec module – Configure interface MACsec (802.1AE) on Edge/Gateway devices
Note
This module is part of the graphiant.naas collection (version 26.5.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install graphiant.naas.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: graphiant.naas.graphiant_macsec.
New in graphiant.naas 26.5.0
Synopsis
Configures MACsec on main LAN interfaces (ethernet or LAG) via
PUT /v1/devices/{device_id}/configunderedge.interfaces.{name}.interface.macsec.macsecoredge.lagInterfaces.{name}.interface.macsec.macsec.Supports enabling/disabling MACsec, configuring encryption enforcement mode, key server priority, pre-shared keys (PSK), and SAK profile settings (replay protection window and rekey interval).
Supply
macsec_config_filefor a bulkmacseclist, and/ordevicewithinterfacesto run a single device or override one device from the file.Add or rotate PSKs with
presharedKeysentries (up to 3 per interface). Each key requires a uniquenickname, futurestartTime(Unix seconds or UTC datetime string such as2029-12-11 11:12:13),cak,ckn, andcipherSuite(AES_128_CMACorAES_256_CMAC). AES-128 requires a 32-digit hex CAK; AES-256 requires 64-digit hex CAK.cknis 2–64 hex digits.Remove a PSK with
state: absenton the key entry (sendspsk: null). At least one PSK must remain when MACsec is enabled.Existing PSK nicknames cannot be updated in place (CAK, CKN, startTime, cipher suite). To rotate, add a new
presharedKeysentry with a unique nickname, then remove the old key withstate: absent. Listing an unchanged existing key in YAML is idempotent and does not re-push the PSK.CAK is sensitive. Omit
cakfrom YAML orinterfaces; setckn(plaintext) on each presharedKeys entry and supplyvault_devices_macsec_psk(device → interface → ckn → cak) via Ansible Vault. Or setcakin YAML/module params for dev/local only. Diff output redacts CAK values and usescakConfiguredbooleans.Idempotent merge per interface field. Partial updates are supported (e.g.
enabled: false,keyServerPriorityonly, PSK rotation, SAK-only). Configure-only (no deconfigure operation).Requires a software image with MACsec support on the target device. The API returns an error when MACsec is unsupported on the device image.
Requirements
The below requirements are needed on the host that executes this module.
python >= 3.7
graphiant-sdk >= 26.5.0
Parameters
Parameter |
Comments |
|---|---|
Bearer token for API authentication (for example, from If not passed as a module argument, the collection reads When a bearer token is present (module argument or environment), it takes precedence over If no valid token is available, the module authenticates with |
|
Enable detailed logging in the task result message. Choices:
|
|
Portal device hostname for Required when |
|
Graphiant portal host URL for API connectivity. Example: “https://api.graphiant.com” |
|
Map of main interface name to MACsec settings (ethernet or LAG only; not subinterfaces). Each value may include |
|
Path to YAML (optional if Relative paths resolve using the collection config path (see Top-level key |
|
Only Choices:
|
|
Graphiant portal password for authentication. Required for password-based login when no valid bearer token is available from |
|
Only Choices:
|
|
Graphiant portal username for authentication. Required for password-based login when no valid bearer token is available from |
|
Nested map Default: |
Attributes
Attribute |
Support |
Description |
|---|---|---|
Support: full |
Supports check mode similarly to other device config modules. |
|
Support: full |
Supports Ansible’s |
Notes
Note
Configuration files support Jinja2 templating syntax for dynamic value substitution.
When using
macsec_config_file, setcknon each key in YAML, omitcak, and passvault_devices_macsec_pskloaded fromconfigs/vault_secrets.yml(seeplaybooks/macsec_management.yml). Plaintextcakin YAML is for dev/local testing only.With
ansible-playbook --check, writes are skipped butchangedreflects whether an apply would update at least one device. Use--diffto previewdetails.diff_planand Ansiblediff.Use graphiant.naas.graphiant_macsec_info to query MACsec monitoring status (
GET /v2/monitoring/macsec/{device_id}/status).
See Also
See also
- graphiant.naas.graphiant_macsec_info
Query MACsec secure/unsecure monitoring status per interface.
- graphiant.naas.graphiant_interfaces
Configure LAN/WAN interfaces before applying MACsec.
- graphiant.naas.graphiant_lag_interfaces
Configure LAG interfaces before applying MACsec on LAGs.
Examples
# Load vault_secrets.yml with M(ansible.builtin.include_vars) first (see macsec_management.yml).
- name: Apply MACsec from sample_macsec.yaml
graphiant.naas.graphiant_macsec:
operation: configure
macsec_config_file: "sample_macsec.yaml"
vault_devices_macsec_psk: "{{ vault_devices_macsec_psk | default({}) }}"
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
detailed_logs: true
register: macsec_result
no_log: true
- name: Enable MACsec on a LAG interface (secrets from vault or module params)
graphiant.naas.graphiant_macsec:
operation: configure
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
device: "edge-1-sdktest"
vault_devices_macsec_psk: "{{ vault_devices_macsec_psk | default({}) }}"
interfaces:
LAG1:
enabled: true
encryptionEnforcementMode: MACSEC_ENFORCEMENT_MODE_MUST_ENCRYPT
keyServerPriority: 200
presharedKeys:
- nickname: macsec-key-1
startTime: "2029-12-11 11:12:13"
ckn: "853c6a4eb4f21c58a5bfeb9600dd26e8e045ded866b02a45f5f52cebadcd5956"
cipherSuite: AES_256_CMAC
useXpnForCipherSuite: true
sakConfiguration:
replayProtectionWindowSize: 64
rekeyInterval: 3600
no_log: true
- name: Disable MACsec on an interface
graphiant.naas.graphiant_macsec:
operation: configure
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
device: "edge-1-sdktest"
interfaces:
LAG1:
enabled: false
- name: Rotate MACsec keys (add new key, remove old)
graphiant.naas.graphiant_macsec:
operation: configure
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
device: "edge-1-sdktest"
interfaces:
GigabitEthernet7/0/0:
presharedKeys:
- nickname: key1
state: absent
- nickname: key2
startTime: "2029-12-11 23:12:13"
ckn: "24"
cipherSuite: AES_256_CMAC
vault_devices_macsec_psk: "{{ vault_devices_macsec_psk | default({}) }}"
no_log: true
- name: Update SAK replay window only
graphiant.naas.graphiant_macsec:
operation: configure
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
device: "edge-1-sdktest"
interfaces:
LAG1:
sakConfiguration:
replayProtectionWindowSize: 128
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
Whether configuration was pushed to at least one device. Returned: always |
|
Device names where an update was applied. Returned: when supported |
|
Structured payload from the manager (device lists, Returned: always |
|
Ansible Returned: when playbook uses |
|
Path to the YAML file used, if any. Returned: when provided |
|
Human-readable result (includes detailed logs when enabled). Returned: always |
|
Operation performed (always Returned: always |
|
Device names skipped because state already matched. Returned: when supported |