This role installs and configures LXC on a server. The user can specify dnsmasq IP parameters for DNS and DHCP purpose. This playbook is only compatible for Debian.
This role requires Ansible 1.4 or higher and platform requirements are listed in the metadata file.
The variables that can be passed to this role and a brief description about them are as follows.
# The DNS domain where LXC containers should belong to
lxc_domain: mydomain.lan
# The subnet for DHCP server served by dnsmasq
lxc_ipnet: 192.168.0.0/24
# The DHCP range served by dnsmasq with the lease time
lxc_dhcp_range: 192.168.0.50,192.168.0.200,1h
# Set network mode: nat or bridge
lxc_network_mode: lxc-net
You can also set specific parameters depending the host configuration you want to give. Here is an example
[servers]
bridge.server.lan lxcbr0_ip=10.0.0.1 lxc_ipnet=10.0.0.0/24 lxc_dhcp_range=10.0.0.200,10.0.0.220,1h lxc_network_mode=bridge
nat.server.lan lxcbr0_ip=192.168.0.1 lxc_ipnet=192.168.0.0/24 lxc_dhcp_range=192.168.0.200,192.168.0.220,1h lxc_network_mode=lxc-net
This roles setup network for containers in one of the following mode:
lxc-net
: setuplxc-net
service for NAT, DHCP and DNS resolution.nat
: Create a dedicatedlxcbr0
in/etc/network/interfaces.d
and setup NAT withiptables
. Withlxc_tight_dedicated_dnsmasq: yes
, you have a dedicated DHCP server for your containers. This is an Ansible implementation oflxc-net
service.bridge
: takes control of/etc/network/interfaces
, creates alxcbr0
bridge witheth0
in. This allow to share containers to the world, without NAT.
Having DNS resolution of container is very confortable. The idea is to have a
dnsmasq
running on host with a DNS delegation for .lxc
domains to a
dedicated dnsmasq
instance managing containers IP and names.
A wildcard record is registerd for the host. All containers can resolve host IP
in container network with e.g. lxchost.lxc
.
# Roles
- name: deploy lxc
hosts: servers
user: root
roles:
- lxc
vars:
- lxc_template_path: /tmp/lxc-debian-wheezy-template
- lxc_domain: lxc
- lxc_ipnet: 192.168.0.0/24
- lxc_dhcp_range: 192.168.0.50,192.168.0.200,1h
- lxcbr0_ip: 192.168.0.1
- lxcbr0_netmask: 255.255.255.0
- lxc_network_mode: lxc-net
None
GPL
Pierre Mavro / deimosfr