-
Notifications
You must be signed in to change notification settings - Fork 0
/
safe-remove.yml
executable file
·58 lines (48 loc) · 1.34 KB
/
safe-remove.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/ansible-playbook
---
#
# Safely removes the chroot directory created by init-arcade.yml.
#
# In particular, it removes any bind mounts before recursively
# deleting the chroot directory.
#
# To run:
# sudo safe-remove.yml -e cli_chroot_path=/path/to/chroot
#
- hosts: localhost
connection: local
vars:
bind_mounts:
- proc
- sys
- dev/pts
- dev
tasks:
- name: Check if user is root
fail:
msg: "This playbook must be run as root"
when: ansible_user_uid != 0
- name: Check for required variables
fail:
msg: "Variable {{ item }} is not defined"
when: item is undefined
with_items:
- cli_chroot_path
- name: Confirm deletion
pause:
prompt: |
Proceed with deletion of {{ cli_chroot_path }}?
To continue, press Enter. To stop, press Ctrl-C and then 'A' to abort.
- name: Find existing bind mounts in chroot directory
command: "findmnt --mountpoint {{ cli_chroot_path }}/{{ item }}"
register: bind_mount_status
ignore_errors: yes
with_items: "{{ bind_mounts }}"
- name: Remove bind mounts in chroot directory
command: "umount {{ cli_chroot_path }}/{{ item.item }}"
when: item.rc == 0
with_items: "{{ bind_mount_status.results }}"
- name: Remove chroot directory
file:
path: "{{ cli_chroot_path }}"
state: absent