Skip to content

mrlesmithjr/ansible-netplan

ansible-netplan

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

ansible-galaxy install mrlesmithjr.netplan

Supported Platforms

Platform Versions
Ubuntu 18.04, 20.04, 22.04, 24.04
Debian 11, 12

Requirements

Run with become: true. The netplan.io package is installed automatically.

Quick Start

---
- 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

Key Variables

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

Configuration Examples

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: enp3s0

WireGuard (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_configuration to be evaluated correctly.

See defaults/main.yml for the full variable reference including VLANs, bridges, and WiFi.

Testing

pip install molecule molecule-docker
molecule test

Support This Project

If your organization uses this role in production, consider sponsoring its maintenance. Enterprise support tiers are available.

License

MIT

Author

Larry Smith Jr. — everythingshouldbevirtual.com · mrlesmithjr@gmail.com

About

Ansible role to manage Netplan

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages