diff --git a/roles/educontainer/tasks/main.yml b/roles/educontainer/tasks/main.yml index 1f503b2..6cc80b3 100644 --- a/roles/educontainer/tasks/main.yml +++ b/roles/educontainer/tasks/main.yml @@ -88,10 +88,11 @@ - { src: systemd-networkd.socket, dest: sockets.target.wants/systemd-networkd.socket } - { src: systemd-networkd-wait-online.service, dest: network-online.target.wants/systemd-networkd-wait-online.service } -- name: clone the initial container - command: machinectl clone {{ contname }}00 {{ contname }}{{ "%02d" | format(item|int) }} - args: - creates: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }} +- name: generate links to the initial container + file: + src: "{{ contname }}00" + dest: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }} + state: link loop: "{{ containers[1:] }}" - name: provide container configuration @@ -100,15 +101,21 @@ dest: /etc/systemd/nspawn/{{ contname}}{{ "%02d" | format(item|int) }}.nspawn loop: "{{ containers }}" -- name: provide container hostname +- name: provide container hostname file template: src: hostname.j2 - dest: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}/etc/hostname + dest: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}.hostname + loop: "{{ containers }}" + +- name: provide container hosts file + template: + src: hosts.j2 + dest: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}.hosts loop: "{{ containers }}" - name: start all containers on boot systemd: name: systemd-nspawn@{{ contname }}{{ "%02d" | format(item|int) }}.service - state: started + state: restarted enabled: yes loop: "{{ containers }}" diff --git a/roles/educontainer/templates/contcfg.nspawn.j2 b/roles/educontainer/templates/contcfg.nspawn.j2 index c436224..c15c32f 100644 --- a/roles/educontainer/templates/contcfg.nspawn.j2 +++ b/roles/educontainer/templates/contcfg.nspawn.j2 @@ -9,3 +9,5 @@ Port=10{{ "%03d" | format(item|int + 100) }}:80 [Files] Volatile=overlay PrivateUsersChown=false +BindReadOnly=/var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}.hostname:/etc/hostname +BindReadOnly=/var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}.hosts:/etc/hosts diff --git a/roles/educontainer/templates/hosts.j2 b/roles/educontainer/templates/hosts.j2 new file mode 100644 index 0000000..9767fea --- /dev/null +++ b/roles/educontainer/templates/hosts.j2 @@ -0,0 +1,4 @@ +127.0.0.1 localhost {{ contname }}{{ "%02d" | format(item|int) }} +::1 localhost {{ contname }}{{ "%02d" | format(item|int) }} ip6-localhost ip6-loopback +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters