avinetworks.network_interface

Network Interface

Warning: This role can be risky. If you lose network connection to your target machine due to incorrect settings, recovering might require physical access to the device.

This role lets users set up different network components on target machines. You can configure:

  • Ethernet interfaces
  • Bridge interfaces
  • Bonded interfaces
  • VLAN tagged interfaces
  • Network routes

Requirements

This role needs Ansible version 1.4 or higher. Platform requirements are specified in the metadata file.

Role Variables

You can provide the following variables to this role:

Variable Required Default Comments
network_pkgs No [] Necessary packages like selinux, bridge-utils, ifenslave, and iproute.
network_ether_interfaces No [] List of Ethernet interfaces to add to the system.
network_bridge_interfaces No [] List of bridge interfaces to add to the system.
network_bond_interfaces No [] List of bonded interfaces to add to the system.
network_vlan_interfaces No [] List of VLAN interfaces to add to the system.
network_check_packages No true Install packages specified in network_pkgs.
network_allow_service_restart No true Allow reconfiguration and restart of interfaces/network.
network_modprobe_persist No true Keep modules loaded after setup.
network_configured_interfaces_only No false If enabled, removes interfaces not configured by this role.
network_interface_file_prefix No ifcfg- Prefix for interface configuration files.
network_interface_file_postfix No `` Postfix for interface configuration files.

Note: Specific values for the lists are provided in the examples below.

Examples

In Debian (not RedHat), you can use CIDR notation for IPv4 addresses instead of separate address and subnet mask inputs. CIDR notation is required for IPv6 addresses on Debian.

IPv4 Example with CIDR Notation:

      cidr: 192.168.10.18/24
      gateway: auto  # Optional: specify a gateway, or use auto for network+1

IPv4 Example with Traditional Format:

      address: 192.168.10.18
      netmask: 255.255.255.0
      network: 192.168.10.0
      broadcast: 192.168.10.255
      gateway: 192.168.10.1

Setting a Different MAC Address:

      hwaddress: aa:bb:cc:dd:ee:ff

Custom Options:

      options:
          - "up /execute/my/command"
          - "down /execute/my/other/command"

IPv6 version:

      ipv6_options:
          - "up /execute/my/command"
          - "down /execute/my/other/command"

Configure eth1 and eth2 with Static and DHCP IPs:

- hosts: myhost
  roles:
    - role: network
      network_ether_interfaces:
       - device: eth1
         bootproto: static
         cidr: 192.168.10.18/24
         gateway: auto
         route:
          - network: 192.168.200.0
            netmask: 255.255.255.0
            gateway: 192.168.10.1
          - network: 192.168.100.0
            netmask: 255.255.255.0
            gateway: 192.168.10.1
       - device: eth2
         bootproto: dhcp

(Note: Adding routes is optional; the default route will be added automatically.)

Configure a Bridge Interface:

- hosts: myhost
  roles:
    - role: network
      network_bridge_interfaces:
       - device: br1
         type: bridge
         cidr: 192.168.10.10/24
         bridge_ports: [eth1, eth2]
         # Optional settings
         bridge_ageing: 300
         bridge_bridgeprio: 32768

Configure a Bonded Interface (Active-Backup):

- hosts: myhost
  roles:
    - role: network
      network_bond_interfaces:
        - device: bond0
          address: 192.168.10.128
          netmask: 255.255.255.0
          bond_mode: active-backup
          bond_slaves: [eth1, eth2]

Configure a Bonded Interface (802.3ad with DHCP):

- hosts: myhost
  roles:
    - role: network
      network_bond_interfaces:
        - device: bond0
          bootproto: dhcp
          bond_mode: 802.3ad

Configure a VLAN Interface:

- hosts: myhost
  roles:
    - role: network
      network_ether_interfaces:
       - device: eth1
         bootproto: static
         cidr: 192.168.10.18/24
      network_vlan_interfaces:
       - device: eth1.2
         bootproto: static
         cidr: 192.168.20.18/24

Configure Multiple Hosts:

Example host inventory:

[dc1]
host1
host2

Network Configuration for Each Host:

For host1:

network_ether_interfaces:
   - device: eth1
     bootproto: static
     address: 192.168.10.18
     netmask: 255.255.255.0
     gateway: 192.168.10.1
network_bond_interfaces:
    - device: bond0
      bootproto: dhcp
      bond_mode: 802.3ad

For host2:

network_ether_interfaces:
   - device: eth0
     bootproto: static
     address: 192.168.10.18
     netmask: 255.255.255.0
     gateway: 192.168.10.1

Add DNS Configurations (If Using resolvconf):

dns-nameserver: [ "8.8.8.8", "8.8.4.4" ]
dns-search: "search.mydomain.tdl"
dns-domain: "mydomain.tdl"

Add IPv6 Static IP Configuration:

ipv6_address: "aaaa:bbbb:cccc:dddd:dead:beef::1/64"
ipv6_gateway: "aaaa:bbbb:cccc:dddd::1"

Run the Playbook for All Hosts:

- hosts: all
  roles:
    - role: network

Manage Firewalld Zones:

This role can add network interfaces to firewalld zones. If you use both this role and the firewalld module, be cautious as it may lead to conflicting changes.

Example for adding eth0 to the public firewalld zone:

- device: eth0
  bootproto: static
  address: 192.168.10.18
  netmask: 255.255.255.0
  gateway: 192.168.10.1
  firewalld_zone: public

Note: Ensure network connectivity throughout the playbook process. Keep a control interface unchanged while modifying IPs for stable Ansible connection. Network changes happen in a single script, briefly interrupting connectivity.

Dependencies

python-netaddr

License

BSD

Author Information

Originally created by Benno Joy. Upgrades by several contributors including:

  • Martin Verges
  • Eric Anderson
  • Luke Short
  • Wei Tie

See the full list of contributors here.

Informazioni sul progetto

This roles enables users to configure various network components on target machines.

Installa
ansible-galaxy install avinetworks.network_interface
Licenza
Unknown
Download
7.3k
Proprietario