Move container restart task to handlers.
This commit is contained in:
parent
fcb2e99cc5
commit
85836e311e
2 changed files with 17 additions and 8 deletions
7
roles/educontainer/handlers/main.yml
Normal file
7
roles/educontainer/handlers/main.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
- name: enable and restart containers
|
||||||
|
systemd:
|
||||||
|
name: systemd-nspawn@{{ contname }}{{ "%02d" | format(item|int) }}.service
|
||||||
|
state: restarted
|
||||||
|
enabled: yes
|
||||||
|
loop: "{{ containers }}"
|
||||||
|
listen: enable and restart containers
|
|
@ -6,7 +6,7 @@
|
||||||
## container 1: ssh → host port 10001, HTTP → 10101
|
## container 1: ssh → host port 10001, HTTP → 10101
|
||||||
## ... ... ...
|
## ... ... ...
|
||||||
##
|
##
|
||||||
## User 'ansible' in the sudo group. Password is empty.
|
## User 'ansible' in the sudo group. Password is {{ contpwd }}.
|
||||||
##
|
##
|
||||||
|
|
||||||
- name: stop all containers
|
- name: stop all containers
|
||||||
|
@ -68,6 +68,7 @@
|
||||||
creates: /var/lib/machines/{{ contname }}00
|
creates: /var/lib/machines/{{ contname }}00
|
||||||
environment:
|
environment:
|
||||||
http_proxy: http://localhost:3142
|
http_proxy: http://localhost:3142
|
||||||
|
notify: enable and restart containers
|
||||||
|
|
||||||
- name: provide complete apt sources
|
- name: provide complete apt sources
|
||||||
copy:
|
copy:
|
||||||
|
@ -127,6 +128,7 @@
|
||||||
- multi-user.target.wants
|
- multi-user.target.wants
|
||||||
- sockets.target.wants
|
- sockets.target.wants
|
||||||
- network-online.target.wants
|
- network-online.target.wants
|
||||||
|
notify: enable and restart containers
|
||||||
|
|
||||||
- name: enable systemd-networkd service
|
- name: enable systemd-networkd service
|
||||||
file:
|
file:
|
||||||
|
@ -139,6 +141,9 @@
|
||||||
- { src: systemd-networkd.service, dest: multi-user.target.wants/systemd-networkd.service }
|
- { src: systemd-networkd.service, dest: multi-user.target.wants/systemd-networkd.service }
|
||||||
- { src: systemd-networkd.socket, dest: sockets.target.wants/systemd-networkd.socket }
|
- { 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 }
|
- { src: systemd-networkd-wait-online.service, dest: network-online.target.wants/systemd-networkd-wait-online.service }
|
||||||
|
notify: enable and restart containers
|
||||||
|
|
||||||
|
########
|
||||||
|
|
||||||
- name: generate links to the initial container
|
- name: generate links to the initial container
|
||||||
file:
|
file:
|
||||||
|
@ -146,28 +151,25 @@
|
||||||
dest: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}
|
dest: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}
|
||||||
state: link
|
state: link
|
||||||
loop: "{{ containers[1:] }}"
|
loop: "{{ containers[1:] }}"
|
||||||
|
notify: enable and restart containers
|
||||||
|
|
||||||
- name: provide container configuration
|
- name: provide container configuration
|
||||||
template:
|
template:
|
||||||
src: contcfg.nspawn.j2
|
src: contcfg.nspawn.j2
|
||||||
dest: /etc/systemd/nspawn/{{ contname}}{{ "%02d" | format(item|int) }}.nspawn
|
dest: /etc/systemd/nspawn/{{ contname}}{{ "%02d" | format(item|int) }}.nspawn
|
||||||
loop: "{{ containers }}"
|
loop: "{{ containers }}"
|
||||||
|
notify: enable and restart containers
|
||||||
|
|
||||||
- name: provide container hostname file
|
- name: provide container hostname file
|
||||||
template:
|
template:
|
||||||
src: hostname.j2
|
src: hostname.j2
|
||||||
dest: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}.hostname
|
dest: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}.hostname
|
||||||
loop: "{{ containers }}"
|
loop: "{{ containers }}"
|
||||||
|
notify: enable and restart containers
|
||||||
|
|
||||||
- name: provide container hosts file
|
- name: provide container hosts file
|
||||||
template:
|
template:
|
||||||
src: hosts.j2
|
src: hosts.j2
|
||||||
dest: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}.hosts
|
dest: /var/lib/machines/{{ contname }}{{ "%02d" | format(item|int) }}.hosts
|
||||||
loop: "{{ containers }}"
|
loop: "{{ containers }}"
|
||||||
|
notify: enable and restart containers
|
||||||
- name: start all containers on boot and restart now
|
|
||||||
systemd:
|
|
||||||
name: systemd-nspawn@{{ contname }}{{ "%02d" | format(item|int) }}.service
|
|
||||||
state: restarted
|
|
||||||
enabled: yes
|
|
||||||
loop: "{{ containers }}"
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue