community.openwrt.wg_peer module – Manage WireGuard/AmneziaWG peer UCI sections
Note
This module is part of the community.openwrt collection (version 1.11.0).
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 community.openwrt.
To use it in a playbook, specify: community.openwrt.wg_peer.
New in community.openwrt 1.10.0
Synopsis
Writes WireGuard/AmneziaWG peer UCI sections for an interface.
Takes the peer’s resolved key material (public key, optional PSK, endpoint) from controller facts; the interface itself must already exist (see community.openwrt.wg_interface).
Note
This module has a corresponding action plugin.
Parameters
Parameter |
Comments |
|---|---|
Ucode template for the peer UCI section id. Rendered with these variables in scope: Default: |
|
List of peer configurations to write. Each suboption below sets the UCI option of the same name. When a suboption with no default is not set, that option is removed from an existing peer section. Other options of the section are left alone. |
|
List of allowed IPs/prefixes. Default: |
|
Peer description/label. Defaults to |
|
Peer endpoint host. Empty to omit (spoke does not dial). |
|
Peer endpoint port. |
|
Parent interface name. |
|
Peer persistent keepalive interval. The option is omitted when not set. |
|
Peer pre-shared key (optional). Never generated by this module; it is supplied by the caller (resolved/shared by community.openwrt.wg_interface). When not set, any pre-shared key already present in the peer section is removed. |
|
Peer protocol; the peer section type becomes Defaults to the When the protocol of an existing peer section changes, its type is changed in place. Choices:
|
|
Peer public key. Required when the peer state is |
|
Whether to add routes for the peer’s allowed IPs (OpenWrt Choices:
|
|
Peer section suffix, available as |
|
Whether the peer section should be present or absent. When Defaults to the module-wide Choices:
|
|
Module-wide protocol, used for every peer whose own
Choices:
|
|
Module-wide state, used as the default for every peer whose own An explicitly-set Choices:
|
Attributes
Attribute |
Support |
Description |
|---|---|---|
Support: full |
Can run in |
|
Support: full |
Returns details on what has changed (or possibly needs changing in |
|
Platform: OpenWrt |
Target platform for this module. |
Notes
Note
This module writes peer UCI sections only; it does not establish tunnels.
Set the
no_logtask keyword on tasks passingpeers[].preshared_key, to keep the pre-shared keys out of the output and logs.The peer section ID is rendered from
peer_id_templateand must match the ID used by community.openwrt.wg_interface when resolving pre-shared keys.Template options (
peer_id_template) use ucode’s native template engine (Jinja-style{{ ... }}/{% ... %}).
See Also
See also
- community.openwrt.wg_interface
Manage WireGuard/AmneziaWG identity keys, interface UCI sections and WAN ingress firewall rules.
Examples
# Hub: write peer sections for two spokes on the wg0 interface
- community.openwrt.wg_peer:
peers:
- iface: wg0
section: spoke1
public_key: "AFakeSpoke1PublicKey"
preshared_key: "AFakeSpoke1Psk"
endpoint_host: "spoke1.example.com"
endpoint_port: 51820
allowed_ips:
- "10.8.0.2/32"
- iface: wg0
section: spoke2
public_key: "AFakeSpoke2PublicKey"
preshared_key: "AFakeSpoke2Psk"
endpoint_host: "spoke2.example.com"
endpoint_port: 51820
allowed_ips:
- "10.8.0.3/32"
# Two independent p2p links: one peer per link interface (no section)
- community.openwrt.wg_peer:
peers:
- iface: wg_l1
public_key: "AFakeLink1PeerPublicKey"
preshared_key: "AFakeLink1PeerPsk"
endpoint_host: "link1-peer.example.com"
endpoint_port: 51821
allowed_ips:
- "10.9.0.2/32"
- iface: wg_l2
public_key: "AFakeLink2PeerPublicKey"
preshared_key: "AFakeLink2PeerPsk"
endpoint_host: "link2-peer.example.com"
endpoint_port: 51822
allowed_ips:
- "10.10.0.2/32"
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
Names of the (re)written peer sections. Returned: always |
|
Names of peer sections removed because their Returned: always |