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

Commit 5cf9355

Browse files
committed
Supports lxc-net native service
1 parent ca8a109 commit 5cf9355

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ them are as follows.
2525
# The DHCP range served by dnsmasq with the lease time
2626
lxc_dhcp_range: 192.168.0.50,192.168.0.200,1h
2727
# Set network mode: nat or bridge
28-
lxc_network_mode: bridge
28+
lxc_network_mode: lxc-net
2929
```
3030

3131
You can also set specific parameters depending the host configuration you want
@@ -34,7 +34,7 @@ to give. Here is an example
3434
```
3535
[servers]
3636
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
37-
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=nat
37+
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
3838
```
3939

4040
Examples
@@ -51,12 +51,12 @@ Examples
5151
5252
vars:
5353
- lxc_template_path: /tmp/lxc-debian-wheezy-template
54-
- lxc_domain: mydomain.lan
54+
- lxc_domain: lxc
5555
- lxc_ipnet: 192.168.0.0/24
5656
- lxc_dhcp_range: 192.168.0.50,192.168.0.200,1h
5757
- lxcbr0_ip: 192.168.0.1
5858
- lxcbr0_netmask: 255.255.255.0
59-
- lxc_network_mode: nat
59+
- lxc_network_mode: lxc-net
6060
```
6161

6262
Dependencies

defaults/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ lxc_ipnet: 192.168.0.0/24
66
lxc_dhcp_range: 192.168.0.50,192.168.0.200,1h
77
# The lease file for dnsmasq
88
lxc_dhcp_leasefile: /var/lib/misc/dnsmasq.lxcbr0.leases
9-
# Set network mode: nat or bridge
9+
# Set network mode: nat or bridge or lxc-net
1010
lxc_network_mode: bridge
1111
# Whether to start and stop dnsmasq with iface
1212
lxc_tight_dedicated_dnsmasq: true

tasks/lxc_install.yml

+14
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
template: src=interfaces_bridge.j2 dest=/etc/network/interfaces backup=yes
4949
when: lxc_network_mode == 'bridge'
5050

51+
- name: configure lxc-net
52+
template:
53+
src: lxc-net.j2
54+
dest: /etc/default/lxc-net
55+
register: lxc_net
56+
5157
- name: configure dnsmasq
5258
template: src=dnsmasq.lxc.conf.j2 dest=/etc/dnsmasq.d/lxc.conf owner=root group=root mode=0644
5359
register: dnsmasq
@@ -58,13 +64,21 @@
5864

5965
- name: configure lxcbr0 dnsmasq
6066
template: src=dnsmasq.conf.j2 dest=/etc/dnsmasq.lxcbr0.conf owner=root group=root mode=0644
67+
when: lxc_tight_dedicated_dnsmasq
6168

6269
- name: add LXC template with network
6370
template: src=lxc-template.conf.j2 dest=/etc/lxc/lxc-template.conf owner=root group=root mode=0644
6471

6572
- name: start lxcbr0
73+
when: lxc_network_mode in ('nat', 'bridge')
6674
shell: ifup lxcbr0
6775

76+
- name: start lxc-net
77+
when: lxc_net|changed
78+
service:
79+
name: lxc-net
80+
state: restarted
81+
6882
- name: add lxc-convert
6983
copy: src=lxc-convert dest=/usr/bin/lxc-convert owner=root group=root mode=0755
7084

templates/lxc-net.j2

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
USE_LXC_BRIDGE="true"
2+
LXC_BRIDGE="lxcbr0"
3+
LXC_ADDR="{{ lxcbr0_ip }}"
4+
LXC_NETMASK="{{ lxcbr0_netmask }}"
5+
LXC_NETWORK="{{ lxc_ipnet }}"
6+
LXC_DHCP_RANGE="{{ lxc_dhcp_range }}"
7+
LXC_DHCP_CONFILE=""
8+
LXC_DOMAIN="{{ lxc_domain }}"

0 commit comments

Comments
 (0)