diff --git a/salt/lxc-containers/config b/salt/lxc-containers/config index 625add4..e178672 100644 --- a/salt/lxc-containers/config +++ b/salt/lxc-containers/config @@ -10,9 +10,11 @@ lxc.rootfs.backend = dir lxc.autodev = 1 lxc.kmsg = 0 +{%- set n = 0 %} {%- for net, conf in container['interfaces'].items() %} lxc.network.type={{ conf['type'] }} lxc.network.flags=up +lxc.network.hwaddr={{ hwaddr_prefix }}:{{ n.__str()__.rjust(2, '0') }} {%- if conf['type'] == 'veth' %} lxc.network.veth.pair={{ id }}-{{ net }} {%- endif %} @@ -34,6 +36,8 @@ lxc.network.ipv4.gateway={{ pillar['hosts-inet'][net][gw] }} {%- endif %} #lxc.network.ipv6= #lxc.network.ipv6.gateway=fe80::1 + +{%- set n = n + 1 %} {%- endfor %} diff --git a/salt/lxc-containers/init.sls b/salt/lxc-containers/init.sls index 87e8779..f9e201d 100644 --- a/salt/lxc-containers/init.sls +++ b/salt/lxc-containers/init.sls @@ -1,7 +1,8 @@ lxc: pkg.installed: [] -{% for id, container in pillar['containers'].items() %} +{%- set n = 0 %} +{%- for id, container in pillar['containers'].items() %} /var/lib/lxc/{{ id }}: cmd.run: @@ -17,6 +18,7 @@ lxc: - context: id: {{ id }} container: {{ container }} + hwaddr_prefix: '0A:14:48:01:{{ n.__str__().rjust(2, '0') }}' - require: - cmd: /var/lib/lxc/{{ id }} @@ -55,4 +57,5 @@ start-{{ id }}: require: - service: autostart-{{ id }} +{%- set n = n + 1 %} {% endfor %}