Instead of cloning the image, link to the rootfs. Provide more individual files.

This commit is contained in:
Andreas B. Mundt 2021-11-11 18:40:14 +01:00 committed by Andreas B. Mundt
parent b920bdf52b
commit fed5f71357
3 changed files with 20 additions and 7 deletions

View file

@ -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 }}"

View file

@ -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

View file

@ -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