graphiant.naas.graphiant_dhcp_relay module – Manage Graphiant DHCP relay on interfaces and subinterfaces
Note
This module is part of the graphiant.naas collection (version 26.7.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_dhcp_relay.
New in graphiant.naas 26.7.0
Synopsis
Configures DHCP relay (IPv4 and/or IPv6) on main interfaces and VLAN subinterfaces via
PUT /v1/devices/{device_id}/configunderedge.interfaces.{name}.interface.ipv4.dhcp.dhcpRelayand the IPv6 equivalent.Supports configure and deconfigure operations. Deconfigure sets
relayServers: []for the address families listed in the config file (idempotent when relay is already removed).Configuration files support Jinja2 templating for dynamic generation.
Configure idempotency: compares intended relay servers to existing device state per interface and address family; skips push when already matched (
changed=false).Validates that each referenced main interface or VLAN subinterface exists on the device before pushing; fails with a list of known interfaces when not found.
Mutual exclusion: an interface supports either DHCP relay or a DHCP subnet (server), not both. Configure fails with a clear error if the target interface already has a DHCP subnet configured. Remove the DHCP subnet first using graphiant.naas.graphiant_edge_services with
state: absentbefore enabling DHCP relay on that interface.
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 output for troubleshooting and monitoring. Choices:
|
|
Portal device hostname for single-device or loop execution. When combined with Required when |
|
Path to the DHCP relay configuration YAML file. Optional when Can be an absolute path or relative path. Relative paths are resolved using the configured config_path. File must contain a |
|
List of IPv4 DHCP relay server addresses for the interface named by Ignored when |
|
List of IPv6 DHCP relay server addresses for the interface named by Ignored when |
|
Graphiant portal host URL for API connectivity. Example: “https://api.graphiant.com” |
|
List of interface entries for multi-interface module-param mode. Each entry may contain When set, takes precedence over |
|
Interface name for single-interface module-param mode (e.g. Required when |
|
The specific DHCP relay operation to perform.
Choices:
|
|
Graphiant portal password for authentication. Required for password-based login when no valid bearer token is available from |
|
Graphiant portal username for authentication. Required for password-based login when no valid bearer token is available from |
|
VLAN ID for subinterface relay. Omit for main interface. Used together with |
Attributes
Attribute |
Support |
Description |
|---|---|---|
Support: full In check mode, no configuration is pushed to devices, but the module still reads current device state to determine whether changes would be made. Payloads that would be pushed are logged with a |
Supports check mode. |
|
Support: full With |
Supports diff mode. |
Notes
Note
Check mode (
--check): No config is pushed; payloads that would be pushed are logged with[check_mode].changedreflects whether an apply would update at least one device.Interfaces must be configured first using graphiant.naas.graphiant_interfaces before applying DHCP relay.
Multiple relay entries for the same parent interface (different VLAN subinterfaces) are merged into a single device PUT payload.
See Also
See also
- graphiant.naas.graphiant_interfaces
Configure interfaces before setting up DHCP relay
Examples
# --- From YAML config file ---
- name: Configure DHCP relay on interfaces (from YAML)
graphiant.naas.graphiant_dhcp_relay:
operation: configure
dhcp_relay_config_file: "sample_dhcp_relay_config.yaml"
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
detailed_logs: true
- name: Deconfigure DHCP relay from interfaces (from YAML)
graphiant.naas.graphiant_dhcp_relay:
operation: deconfigure
dhcp_relay_config_file: "sample_dhcp_relay_config.yaml"
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
# --- Single device, single interface from module parameters ---
- name: Configure DHCP relay on a single interface (module params)
graphiant.naas.graphiant_dhcp_relay:
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
operation: configure
device: "edge-1-sdktest"
name: "GigabitEthernet4/0/0"
vlan: 1
dhcpRelayIpv4:
- 10.1.1.1
- 10.2.1.1
dhcpRelayIpv6:
- 2001:10:1:1::1
- name: Deconfigure DHCP relay on a single interface (module params)
graphiant.naas.graphiant_dhcp_relay:
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
operation: deconfigure
device: "edge-1-sdktest"
name: "GigabitEthernet4/0/0"
vlan: 1
dhcpRelayIpv4:
- 10.1.1.1
# --- Single device, multiple interfaces from module parameters ---
- name: Configure DHCP relay on multiple interfaces (module params)
graphiant.naas.graphiant_dhcp_relay:
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
operation: configure
device: "edge-1-sdktest"
interfaces:
- name: GigabitEthernet4/0/0
vlan: 1
dhcpRelayIpv4:
- 10.1.1.1
- 10.2.1.1
dhcpRelayIpv6:
- 2001:10:1:1::1
- name: GigabitEthernet8/0/0
dhcpRelayIpv4:
- 10.1.11.1
- 10.2.11.1
# --- Loop over multiple devices (one interface per iteration) ---
- name: Configure DHCP relay on multiple devices (loop)
graphiant.naas.graphiant_dhcp_relay:
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
operation: configure
device: "{{ item.device }}"
name: "{{ item.name }}"
vlan: "{{ item.vlan | default(omit) }}"
dhcpRelayIpv4: "{{ item.dhcpRelayIpv4 | default(omit) }}"
dhcpRelayIpv6: "{{ item.dhcpRelayIpv6 | default(omit) }}"
loop:
- device: edge-1-sdktest
name: GigabitEthernet4/0/0
vlan: 1
dhcpRelayIpv4: ["10.1.1.1", "10.2.1.1"]
dhcpRelayIpv6: ["2001:10:1:1::1"]
- device: edge-2-sdktest
name: GigabitEthernet8/0/0
dhcpRelayIpv4: ["10.1.11.1"]
# --- Override one device from a YAML file ---
- name: Override DHCP relay for one device from file
graphiant.naas.graphiant_dhcp_relay:
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
operation: configure
dhcp_relay_config_file: "sample_dhcp_relay_config.yaml"
device: "edge-1-sdktest"
name: "GigabitEthernet4/0/0"
dhcpRelayIpv4:
- 192.168.1.1
# --- Per-interface state: absent (remove all relay on one interface, configure others) ---
- name: Remove relay from one subinterface while configuring others
graphiant.naas.graphiant_dhcp_relay:
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
operation: configure
device: "edge-3-sdktest"
interfaces:
- name: GigabitEthernet7/0/0
dhcpRelayIpv4:
- 10.2.1.2
- name: GigabitEthernet8/0/0
vlan: 30
state: absent
# --- Per-AF state: absent (remove only IPv4 relay, keep IPv6) ---
- name: Remove IPv4 relay only, keep IPv6 on subinterface
graphiant.naas.graphiant_dhcp_relay:
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
operation: configure
device: "edge-3-sdktest"
interfaces:
- name: GigabitEthernet8/0/0
vlan: 30
dhcpRelayIpv4:
state: absent
dhcpRelayIpv6:
relayServers:
- 2001:10:2:1::2
# --- Check / diff mode ---
- name: Preview DHCP relay changes (check + diff)
graphiant.naas.graphiant_dhcp_relay:
operation: configure
dhcp_relay_config_file: "sample_dhcp_relay_config.yaml"
host: "{{ graphiant_host }}"
username: "{{ graphiant_username }}"
password: "{{ graphiant_password }}"
check_mode: true
diff: true
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
Whether the operation made changes.
In check mode ( Returned: always |
|
Device names where configuration would be or was pushed. Returned: when supported |
|
Raw manager result (includes Returned: when supported |
|
The DHCP relay configuration file used for the operation, if provided. Returned: when provided |
|
Ansible Returned: when playbook uses |
|
Result message from the operation. Returned: always |
|
The operation that was performed. Returned: always |
|
Device names where no DHCP relay changes were needed. Returned: when supported |