Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.


Folders and files

Last commit message
Last commit date

Latest commit



42 Commits

Repository files navigation

Ansible LXC playbook

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.

Role Variables

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
    # The DHCP range served by dnsmasq with the lease time
    # 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

bridge.server.lan lxcbr0_ip= lxc_ipnet= lxc_dhcp_range=,,1h lxc_network_mode=bridge
nat.server.lan lxcbr0_ip= lxc_ipnet= lxc_dhcp_range=,,1h lxc_network_mode=lxc-net

Network modes

This roles setup network for containers in one of the following mode:

  • lxc-net: setup lxc-net service for NAT, DHCP and DNS resolution.
  • nat: Create a dedicated lxcbr0 in /etc/network/interfaces.d and setup NAT with iptables. With lxc_tight_dedicated_dnsmasq: yes, you have a dedicated DHCP server for your containers. This is an Ansible implementation of lxc-net service.
  • bridge: takes control of /etc/network/interfaces, creates a lxcbr0 bridge with eth0 in. This allow to share containers to the world, without NAT.

DNS resolution for containers

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

    - lxc

    - lxc_template_path: /tmp/lxc-debian-wheezy-template
    - lxc_domain: lxc
    - lxc_ipnet:
    - lxc_dhcp_range:,,1h
    - lxcbr0_ip:
    - lxcbr0_netmask:
    - lxc_network_mode: lxc-net





Author Information

Pierre Mavro / deimosfr