2017-04-22 14:27:37 +02:00
|
|
|
- name: Setting default facts check for teardown
|
|
|
|
set_fact:
|
|
|
|
jail_is_no_jail_id: '{{ jail_id|default(False) == False }}'
|
|
|
|
|
2017-03-14 22:43:13 +01:00
|
|
|
- name: Fail when jail_id not specified
|
|
|
|
fail:
|
|
|
|
msg: jail_id must be defined for teardown.yml, bailing out
|
2017-04-22 14:27:37 +02:00
|
|
|
when: jail_is_no_jail_id
|
2017-03-14 22:43:13 +01:00
|
|
|
|
2017-03-09 17:17:13 +01:00
|
|
|
- name: Check if the jail {{ jail_id }} runs
|
|
|
|
set_fact:
|
|
|
|
jail_is_old_running: >-
|
|
|
|
{{ jail_id in running_jail_ids }}
|
|
|
|
|
|
|
|
- name: Terminating jail when running
|
|
|
|
command:
|
|
|
|
/usr/sbin/jail -r {{ jail_id }}
|
|
|
|
when: jail_is_old_running
|
|
|
|
|
2017-03-14 22:43:13 +01:00
|
|
|
- name: Removing config block for {{ jail_id }} from /etc/jail.conf
|
|
|
|
blockinfile:
|
|
|
|
state: absent
|
|
|
|
dest: '/etc/jail.conf'
|
|
|
|
# Keep this line at the bottom so vim can use proper syntax higlighting
|
|
|
|
insertbefore: '^# vim: syn=conf$'
|
|
|
|
marker: '# {mark} ANSIBLE MANAGED BLOCK: {{ jail_id }}'
|
|
|
|
|
2017-03-09 17:17:13 +01:00
|
|
|
- name: Getting mounts under this jail
|
|
|
|
shell:
|
|
|
|
/sbin/mount -p
|
|
|
|
| grep '{{ dynamic_jails_path }}/{{ jail_id }}'
|
|
|
|
| awk '{print $2}'
|
|
|
|
warn=no
|
|
|
|
register: mounts_under_jail
|
|
|
|
|
2017-04-22 14:27:37 +02:00
|
|
|
- name: Setting this jail's root mount point
|
|
|
|
set_fact:
|
|
|
|
_iter_mount_point: '{{ dynamic_jails_path + "/" + jail_id }}'
|
|
|
|
|
2017-03-09 17:17:13 +01:00
|
|
|
- name: Unmounting all mounts from under the jail so it could be destroyed
|
|
|
|
command:
|
|
|
|
/sbin/umount
|
|
|
|
'{{ mountpoint }}'
|
2017-04-22 14:27:37 +02:00
|
|
|
when: mountpoint != _iter_mount_point
|
2017-03-09 17:17:13 +01:00
|
|
|
with_items: '{{ mounts_under_jail.stdout_lines|sort(reverse=True) }}'
|
|
|
|
loop_control:
|
|
|
|
loop_var: mountpoint
|
|
|
|
|
2017-03-14 22:43:13 +01:00
|
|
|
- name: Delete config dir for jail
|
|
|
|
file:
|
|
|
|
path: '{{ dynamic_jails_path }}/configs/{{ jail_id }}'
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: Destroying ZFS dataset {{ dynamic_jails_dataset_name }}/{{ jail_id }}
|
2017-03-09 17:17:13 +01:00
|
|
|
zfs:
|
|
|
|
name: >-
|
|
|
|
{{ dynamic_jails_dataset_name }}/{{ jail_id }}
|
|
|
|
state: absent
|
2017-03-14 22:43:13 +01:00
|
|
|
register: zfs_destroy
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
# Due to a possible bug in the ZFS/FreeBSD kernel, destroying the dataset
|
|
|
|
# sometimes isn't possible after freeing it up. Hence we use '-f'
|
|
|
|
- name: Force-destroying ZFS dataset {{ dynamic_jails_dataset_name }}/{{ jail_id }} because it failed formerly
|
|
|
|
command:
|
|
|
|
/sbin/zfs destroy -f
|
|
|
|
{{ dynamic_jails_dataset_name }}/{{ jail_id }}
|
2017-04-22 14:27:37 +02:00
|
|
|
when: 'zfs_destroy | failed and ": Device busy" in zfs_destroy.msg'
|
2017-03-09 17:17:13 +01:00
|
|
|
|
|
|
|
- name: Removing jail directory
|
|
|
|
file:
|
|
|
|
path: >-
|
|
|
|
{{ dynamic_jails_path }}/{{ jail_id }}
|
|
|
|
state: absent
|
|
|
|
|