Coder Social home page Coder Social logo

ansible-config-interfaces's Introduction

Table of Contents generated with DocToc

ansible-config-interfaces

An Ansible role to configure network interfaces

  • Define dhcp, static, and manual settings
  • Create VLAN, bonds, bridges, and interfaces
  • Create Open vSwitch bridges, bonds, and interfaces

Requirements

See Example Playbook for examples of how to define specific network configurations.

NOTE: If creating Open vSwitch configurations you will need to use the ansible-openvswitch Ansible role

Role Variables

defaults/main.yml

Dependencies

If interface is wireless you will need to define as such as well as provide the SSID and key.

Example Playbook

Example Playbook

Examples

Example (standard) /etc/network/interfaces

# Ansible managed
# Any changes made here will be lost

auto lo
iface lo inet loopback

########## Network Interfaces
auto enp0s3
iface enp0s3 inet dhcp
  pre-up sleep 2

auto enp0s8
iface enp0s8 inet static
  address 192.168.250.10
  netmask 255.255.255.0

# bond0 member
auto enp0s9
iface enp0s9 inet manual
  bond_master bond0

# bond0 member
auto enp0s10
iface enp0s10 inet manual
  bond_master bond0

# br0 member
auto enp0s16
iface enp0s16 inet manual

########## End of Network Interfaces

########## Network Bonds
# Bond Group 0
auto bond0
iface bond0 inet static
  address 192.168.1.10
  netmask 255.255.255.0
  bond_slaves enp0s9 enp010
  bond_primary enp0s9
  bond_mode active-backup
  bond_miimon 100

########## End of Network Bonds


########## Network Bridges
# Bridge 0
auto br0
iface br0 inet static
  address 192.168.1.11
  netmask 255.255.255.0
  bridge_stp off
  bridge_fd 0
  bridge_ports enp0s16

########## End of Network Bridges

dns-nameservers 8.8.8.8 8.8.4.4
dns-search test.vagrant.local

Example (Open vSwitch) /etc/network/interfaces

# Ansible managed
# Any changes made here will be lost

auto lo
iface lo inet loopback

########## Network Interfaces
auto enp0s3
iface enp0s3 inet dhcp
  pre-up sleep 2

auto enp0s8
iface enp0s8 inet static
  address 192.168.250.10
  netmask 255.255.255.0

########## End of Network Interfaces




########## OVS Bonds
# OVS Bond
allow-vmbr0 bond0
iface bond0 inet manual
  ovs_bridge vmbr0
  ovs_type OVSBond
  ovs_bonds enp0s9 enp0s10
  ovs_options bond_mode=active-backup lacp=off

########## End of OVS Bonds

########## OVS Bridges
# OVS Bridge
auto vmbr0
allow-ovs vmbr0
iface vmbr0 inet manual
  ovs_type OVSBridge
  ovs_ports bond0 vlan1

########## End of OVS Bridges

########## OVS Interfaces
# VLAN1
allow-vmbr0 vlan1
iface vlan1 inet static
  address 192.168.250.100
  netmask 255.255.255.0
  ovs_bridge vmbr0
  ovs_type OVSIntPort

########## End of OVS Interfaces

dns-nameservers 8.8.8.8 8.8.4.4
dns-search test.vagrant.local

License

MIT

Author Information

Larry Smith Jr.

Buy Me A Coffee

ansible-config-interfaces's People

Contributors

apatard avatar balaji-dutt avatar goetzk avatar mrlesmithjr avatar roedie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ansible-config-interfaces's Issues

Restart only certain interfaces

Hi,

It would be nice if it would be possible to only restart certain interfaces. With the current setup everything goed haywire when configuring bridges on bonds on vlans.

For instance, my servers come out of the preseed with 2 interfaces in a bond, with an bridge on top. This is used for management. But I also want to add other interfaces/config and only bring those interfaces up.

Greets,

Sander

Auto create a bridge port for each vlan

Hi,

I'm essentially looking to produce the following outcome, where every vlan/port has an interface/bridge created for it.
I had a look at the template but it doesn't seem amenable to this kind of behaviour. Is this functionality you would consider?

required fields: comment, bond, (bridge) number

optional: loop options, mtu

# Create an interface for each pridge port.
{% for bridge in bridge_interfaces %}
# {{ bridge.comment }}

# Create bridge port/vlan
auto {{ bridge.bond }}.{{ bridge.number }}
iface {{ bridge.bond }}.{{ bridge.number }} inet manual
    mtu: {{ bridge.mtu |default(1500) }}
# Create interface attached to bridge port
auto br{{ bridge.number }}
iface br{{ bridge.number }} inet manual
    bridge_ports {{ bridge.bond }}.{{ bridge.number }}
    {% loop options if required %}
    {% existing parameters code %}
{% endif %}

Add Open vSwitch Functionality For Debian

Need to add Open vSwitch functionality for Debian systems. This will allow for the creation of OVS bridges, bonds, and interfaces without using the OVS Ansible modules.

Create a Bridge Member

I'm unsure from the sample playbook how you can create a bridge member. Specifically in the network interface configuration how you can set BRIDGE=br0

- hosts: kvm_hosts
  become: true
  vars:
    config_network_bridges: true
    config_network_interfaces: true
    dns_nameservers:
      - "{{dns_nameserver}}"
    network_bridges:
    - name: 'br0'
      configure: true
      enable: false
      comment: 'Bridge 0'
      method: 'static'
      address: "{{bridge_address}}"
      netmask: '255.255.255.0'
      netmask_cidr: '24'
      gateway: "{{bridge_gateway}}"
      ports:
        - 'br0'
    network_interfaces:
      - name: "{{bridge_interface}}"
        configure: true
        enable: false
        comment: 'br0 member'
        method: manual
  roles:
  - role: mrlesmithjr.config-interfaces

lldp not available in Centos Minimal

TASK [mrlesmithjr.config-interfaces : redhat | Installing Pre-Reqs] **************************************************************************************************************
fatal: [nuc]: FAILED! => {"changed": false, "msg": "No package matching 'lldpd' found available, installed or updated", "rc": 126, "results": ["No package matching 'lldpd' found available, installed or updated"]}
	to retry, use: --limit @/Users/doneill/Downloads/kvm/kvm.retry

PLAY RECAP ***********************************************************************************************************************************************************************
nuc                        : ok=1    changed=0    unreachable=0    failed=1

The package is only available via epel, should the role be updated to include epel?

Allow overriding package install

Is your feature request related to a problem? Please describe.
I'm using your role to configure interfaces on a proxmox (debian based) host. When configuring vlan interfaces, the role attempts to install the package vlan, which conflicts with parts of the proxmox installation.

Right now I have a block on the package using an apt preferences file, but it'd be nice if i could specify a flag not to install the packages.

Describe the solution you'd like
A flag to not install packages

$ sudo cat block_vlans 
Package: vlan
Pin: release *
Pin-Priority: -1

$ sudo apt install vlan
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'pve-manager' instead of 'vlan'
pve-manager is already the newest version (6.4-8).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Defaults

Hi, would it be an idea to modify the defaults so it doesn't config all those interfaces?

It makes it kind of a hassle to manage since by default it configures a lot of interfaces.

I don't mind creating a pull for it.

Regards,

Sander

Allow configuration for `auto`

Is your feature request related to a problem? Please describe.
For a manual Proxmox configuration I needed to set an interface which didn't have auto.

Describe the solution you'd like
Allow configuration of auto through a flag.

Describe alternatives you've considered
None

Additional context
None

Restarting Bridges with --force causes networking to stop

Hi Guys,

I'm testing this role on Ubuntu 16.04 and have found that using --force when restarting bridges with slaved interfaces causes networking to fail, especially bad if you're sshing into the box using the bridge.

The good news (I think) is that it looks like removing --force seems to make things work as expected. Is there a specific reason you're using force for this command?

Role uses ansible.builtin.include which has been removed with Ansible 2.16

Describe the bug
The role's main.yml uses include which has been removed with Ansible 2.16

To Reproduce
Steps to reproduce the behavior:

  1. Install Ansible 2.16 or greater
  2. Create an ansible playbook that uses the role
  3. Run playbook
  4. See error as shown below:
ERROR! [DEPRECATED]: ansible.builtin.include has been removed. Use include_tasks or import_tasks instead. This feature was removed from ansible-core in a release after 2023-05-16. Please update your playbooks.

Expected behavior
The playbook should use include_tasks or import_tasks instead so it can be used with Ansible 2.16 or greater.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.