trixie/roles/educontainer/tasks/main.yml

69 lines
1.6 KiB
YAML
Raw Normal View History

## Prepare minimal systemd-nspawn containers for educational use.
##
## Port mapping to the host:
##
## container 0: ssh → host port 10000, HTTP → 10100
## container 1: ssh → host port 10001, HTTP → 10101
## ... ... ...
##
2021-11-18 20:22:00 +01:00
## User '{{ contuser }}' in the sudo group. Password is '{{ contpwd }}'.
##
- name: stop all containers
2021-11-18 20:18:56 +01:00
systemd:
name: systemd-nspawn@{{ contname }}{{ "%02d" | format(item|int) }}.service
state: stopped
loop: "{{ containers | reverse }}"
2021-11-12 12:42:40 +01:00
tags:
- never
- stop
- reset
- purge
- setup
2021-11-12 12:42:40 +01:00
- name: purge all containers
2021-11-18 20:18:56 +01:00
command:
cmd: machinectl remove {{ contname }}{{ "%02d" | format(item|int) }}
removes: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}
loop: "{{ containers | reverse }}"
tags:
- never
- purge
- setup
2021-11-18 20:18:56 +01:00
- name: remove container overlay
file:
path: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}-delta
state: absent
loop: "{{ containers | reverse }}"
tags:
- never
- reset
2021-11-12 12:42:40 +01:00
- purge
- setup
- name: start all containers
2021-11-18 20:18:56 +01:00
systemd:
name: systemd-nspawn@{{ contname }}{{ "%02d" | format(item|int) }}.service
state: started
loop: "{{ containers | reverse }}"
tags:
- never
- start
- reset
###########
2022-03-16 17:31:37 +01:00
- name: check if container template exists
ansible.builtin.stat:
path: "/var/lib/machines/{{ contname }}00"
register: cont
tags:
- always
- name: import setup.yml tasks
import_tasks: setup.yml
2022-03-16 17:31:37 +01:00
when: cont.stat.isdir is not defined
tags:
- always