From 07ec88eadafcd4be1cda473f2ba676bf21dd6e14 Mon Sep 17 00:00:00 2001 From: Edoardo Putti Date: Sat, 18 Mar 2017 11:51:45 +0100 Subject: [PATCH] Configure vlan on host This commit includes the configuration of vlans on the host for virtual machines. By configuring a bridge on the br0 interface we can host the virtual machine vlan and by setting a vlan on the logical device we can include it into the management vlan. All variables are included from playbook --- prepare_host.yaml | 3 +++ templates/interfaces.j2 | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/prepare_host.yaml b/prepare_host.yaml index c3d520a..ce41771 100644 --- a/prepare_host.yaml +++ b/prepare_host.yaml @@ -1,5 +1,8 @@ --- - hosts: vm_hosts + vars: + management_vlan: 9 + virtual_machine_vlan: 13 tasks: - name: install lxc related packages apt: diff --git a/templates/interfaces.j2 b/templates/interfaces.j2 index 7341e5d..e9bca0f 100644 --- a/templates/interfaces.j2 +++ b/templates/interfaces.j2 @@ -9,9 +9,13 @@ iface lo inet loopback # The primary network interface auto br0 -iface br0 inet static - address {{ ansible_default_ipv4.address }} - netmask 255.255.0.0 - gateway {{ hostvars[ext_gateway]['ansible_host'] }} - bridge_ports eth0 +iface br0 inet manual + bridge_ports eth0.{{ virtual_machine_vlan }} bridge_fd 1 + +auto eth0.{{ management_vlan }} +iface eth0.{{ management_vlan }} inet static + address {{ ansible_default_ipv4.address }} + gateway {{ hostvars[ext_gateway]['ansible_host'] }} + netmask 255.255.255.0 + vlan-raw-device eth0