An Ansible role to manage Netplan network configuration.
This role supports all Netplan configuration keys dynamically via YAML merging — you do not need to wait for role updates to use new Netplan features.
ansible-galaxy install mrlesmithjr.netplan| Platform | Versions |
|---|---|
| Ubuntu | 18.04, 20.04, 22.04, 24.04 |
| Debian | 11, 12 |
Run with become: true. The netplan.io package is installed automatically.
---
- hosts: all
become: true
roles:
- role: mrlesmithjr.netplan
netplan_enabled: true
netplan_config_file: /etc/netplan/ansible-config.yaml
netplan_renderer: networkd
netplan_configuration:
network:
version: 2
ethernets:
enp3s0:
dhcp4: true| Variable | Default | Description |
|---|---|---|
netplan_enabled |
true |
Master switch — set to false to skip all tasks |
netplan_config_file |
/etc/netplan/ansible-config.yaml |
Path to the managed Netplan config file |
netplan_config_file_mode |
0600 |
File permissions for the config file |
netplan_renderer |
"" |
Renderer: networkd or NetworkManager (uses system default if unset) |
netplan_configuration |
{} |
Your Netplan configuration (merged with defaults) |
netplan_apply |
true |
Run netplan apply after configuration changes |
netplan_remove_existing |
false |
Remove existing Netplan config files before writing |
netplan_backup_existing |
false |
Back up existing config files before overwriting |
Static IP:
netplan_configuration:
network:
version: 2
ethernets:
enp3s0:
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [1.1.1.1, 8.8.8.8]Bond:
netplan_configuration:
network:
version: 2
bonds:
bond0:
dhcp4: true
interfaces: [enp3s0, enp4s0]
parameters:
mode: active-backup
primary: enp3s0WireGuard (using vaulted variables):
netplan_configuration:
network:
version: 2
tunnels:
wg0:
mode: wireguard
key: "{{ my_wireguard_private_key }}"
my_wireguard_private_key: !vault |
...Vault-encrypted variables must be defined outside
netplan_configurationto be evaluated correctly.
See defaults/main.yml for the full variable reference including VLANs, bridges, and WiFi.
pip install molecule molecule-docker
molecule testIf your organization uses this role in production, consider sponsoring its maintenance. Enterprise support tiers are available.
MIT
Larry Smith Jr. — everythingshouldbevirtual.com · mrlesmithjr@gmail.com