aruhier.systemd_networkd

Ansible Role: systemd_networkd

This is an Ansible role used to set up systemd-networkd.

Role Variables

# Links
systemd_networkd_link: {}

# Network devices (netdevs)
systemd_networkd_netdev: {}

# Network configurations
systemd_networkd_network: {}

# Should the role restart systemd-networkd to apply changes?
systemd_networkd_apply_config: false

# Enable or disable systemd-resolved
systemd_networkd_enable_resolved: true

# Clean up configuration files that match a prefix
systemd_networkd_cleanup: false
systemd_networkd_cleanup_prefix: ''
systemd_networkd_cleanup_prefix_is_regex: false

Dependencies

None

Example Playbook

  1. Configure a network interface
systemd_networkd_network:
  eth0:
    - Match:
      - Name: "eth0"
    - Network:
      - DHCP: "no"
      - IPv6AcceptRouterAdvertisements: "no"
      - DNS: 8.8.8.8
      - DNS: 8.8.4.4
      - Domains: "your.tld"
      - Address: "192.0.2.176/24"
      - Gateway: "192.0.2.1"
      - Address: "2001:db8::302/64"
      - Address: "fc00:0:0:103::302/64"
      - Gateway: "2001:db8::1"

This creates an eth0.network file in /etc/systemd/network/, and enables systemd-networkd and systemd-resolved.

Each key under systemd_networkd_* corresponds to the filename created. The information under each key is structured according to systemd-networkd documentation, with settings listed as option: value pairs, which become option=value.

  1. Configure a bonding interface
systemd_networkd_netdev:
  bond0:
    - NetDev:
      - Name: "bond0"
      - Kind: "bond"
    - Bond:
      - Mode: "802.3ad"
      - LACPTransmitRate: "fast"

systemd_networkd_network:
  bond0:
    - Match:
      - Name: "eth*"
    - Network:
      - DHCP: "yes"
      - Bond: "bond0"

This sets up an LACP bond interface called bond0, which includes all interfaces starting with eth.

  1. Configure route-based interface
systemd_networkd_conf:
  route_tables:
    - Network:
        - RouteTable: "rtvlan10:10"
        - RouteTable: "rtvlan11:11"

systemd_networkd_netdev:
  netdev_bond0:
    - NetDev:
        - Name: bond0
        - Kind: bond
    - Bond:
        - Mode: active-backup
        - MIIMonitorSec: 0.1
        - UpDelaySec: 0.2
        - DownDelaySec: 0.2
        - LACPTransmitRate: fast
        - TransmitHashPolicy: layer2+3
  netdev_vlan10:
    - NetDev:
        - Name: netdev_vlan10
        - Kind: vlan
    - VLAN:
        - Id: 10
  netdev_vlan11:
    - NetDev:
        - Name: netdev_vlan11
        - Kind: vlan
    - VLAN:
        - Id: 11
  netdev_bridge_vm_vlan10:
    - NetDev:
        - Name: netdev_bridge_vlan10
        - Kind: bridge
  netdev_bridge_vm_vlan11:
    - NetDev:
        - Name: netdev_bridge_vlan11
        - Kind: bridge

systemd_networkd_network:
  # Physical interfaces
  eno3:
    - Match:
        - Name: eno3
    - Network:
        - Bond: bond0
  eno4:
    - Match:
        - Name: eno4
    - Network:
        - Bond: bond0
  bond0:
    - Match:
        - Name: bond0
    - Network:
        - Description: "Static bond for eno3 & eno4"
        - LinkLocalAddressing: "no"
        - LLDP: "no"
        - EmitLLDP: "no"
        - IPv6AcceptRA: "no"
        - IPv6SendRA: "no"
        - VLAN: netdev_vlan10
        - VLAN: netdev_vlan11
  network_interface_vlan10:
    - Match:
        - Name: netdev_vlan10
        - Type: vlan
    - Network:
        - Description: "Interface for VLAN 10 connected to bridge"
        - Bridge: "netdev_bridge_vm_vlan10"
        - DHCP: "no"
        - DNS: &gw_vlan10 "10.0.10.1"
        - Address: "10.0.10.161/24"
        - DNS: *gw_vlan10
        - Gateway: *gw_vlan10
  network_interface_vlan11:
    - Match:
        - Name: netdev_vlan11
        - Type: vlan
    - Network:
        - Description: "Interface for VLAN 11 connected to bridge"
        - Bridge: "netdev_bridge_vm_vlan11"
        - DHCP: "no"
        - DNS: &gw_vlan11 "10.0.11.1"
        - Address: "10.0.11.161/24"
        - DNS: *gw_vlan11
        - Gateway: *gw_vlan11

systemd_networkd_rt_tables:
  - id: 11
    name: rtvlan11
  - id: 20
    name: rtvlan20

systemd-resolved

By default, this role manages the /etc/resolv.conf and /etc/nsswitch.conf files to work with the DNS services provided by systemd-resolved.

You can disable this feature by changing systemd_networkd_symlink_resolv_conf and systemd_networkd_manage_nsswitch_config to false, or you can adjust the resolution order. The standard setup uses the default file and systemd modules as necessary:

systemd_networkd_nsswitch_passwd: "files systemd"
systemd_networkd_nsswitch_group: "files systemd"
systemd_networkd_nsswitch_shadow: "files systemd"
systemd_networkd_nsswitch_gshadow: "files systemd"
systemd_networkd_nsswitch_hosts: "files resolve [!UNAVAIL=return] myhostname dns"
systemd_networkd_nsswitch_networks: "files dns"
systemd_networkd_nsswitch_protocols: "files"
systemd_networkd_nsswitch_services: "files"
systemd_networkd_nsswitch_ethers: "files"
systemd_networkd_nsswitch_rpc: "files"
systemd_networkd_nsswitch_netgroup: "nis"
systemd_networkd_nsswitch_automount: "files"
systemd_networkd_nsswitch_aliases: "files"
systemd_networkd_nsswitch_publickey: "files"

License

This tool is under the BSD license. Feel free to report bugs, ask questions, or submit pull requests!

Informazioni sul progetto

Configures systemd-networkd

Installa
ansible-galaxy install aruhier.systemd_networkd
Licenza
other
Download
2.8k
Proprietario