/
zap_disks.yml
84 lines (73 loc) · 2.84 KB
/
zap_disks.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
# These zap tasks are run on freshly reimaged cobbler_managed machines
# even when using the -stock profiles. Therefore, testnode package
# installation hasn't happened yet so we install zap dependencies here.
- name: Make sure apt dependencies are installed
apt:
name: ['gdisk', 'dmsetup']
state: present
when: ansible_os_family == "Debian"
- name: Make sure rpm dependencies are installed
package:
name: ['gdisk', 'device-mapper']
state: present
when: (ansible_distribution == "RedHat" and rhsm_registered is defined and rhsm_registered == true) or
(ansible_os_family == "RedHat" and ansible_distribution != "RedHat")
- name: Set root disk
set_fact:
root_disk: "{{ item.device|regex_replace('[0-9]+', '') }}"
with_items: "{{ ansible_mounts }}"
when: item.mount == '/'
- name: Compile list of non-root partitions
shell: "lsblk --list --noheadings | grep part | grep -v {{ root_disk|regex_replace('/dev/', '') }} | awk '{ print $1 }'"
register: non_root_partitions
- name: Unmount any non-root mountpoints
mount:
path: "{{ item.mount }}"
state: unmounted
with_items: "{{ ansible_mounts }}"
when:
- item.mount != '/' and
not item.mount is match("/(boot|home|opt|root|srv|tmp|usr/local|var|.snapshots)")
## http://tracker.ceph.com/issues/20533
## Trusty version of wipefs lacks --force option
- name: Wipe filesystems on non-root partitions
shell: "wipefs --force --all /dev/{{ item }} || wipefs --all /dev/{{ item }}"
with_items: "{{ non_root_partitions.stdout_lines }}"
when: non_root_partitions|length > 0
## See https://github.com/ceph/ceph-ansible/issues/759#issue-153248281
- name: Zap all non-root disks
shell: "sgdisk --zap-all /dev/{{ item.key }} || sgdisk --zap-all /dev/{{ item.key }}"
with_dict: "{{ ansible_devices }}"
when:
- item.key not in root_disk
- '"loop" not in item.key'
- '"ram" not in item.key'
- '"sr" not in item.key'
## See https://tracker.ceph.com/issues/22354 and
## https://github.com/ceph/ceph/pull/20400
- name: Blow away lingering OSD data and FSIDs
shell: "dd if=/dev/zero of=/dev/{{ item.key }} bs=1M count=110"
with_dict: "{{ ansible_devices }}"
when:
- item.key not in root_disk
- '"loop" not in item.key'
- '"ram" not in item.key'
- '"sr" not in item.key'
- name: Remove all LVM data
shell: "dmsetup remove_all --force"
register: removed_lvm_data
until: "'Unable to remove' not in removed_lvm_data.stderr"
retries: 5
delay: 1
ignore_errors: true
## See http://tracker.ceph.com/issues/21989
- name: Check for physical volumes
shell: "pvdisplay | grep 'PV Name' | awk '{ print $3 }'"
register: pvs_to_remove
- name: Remove physical volumes
shell: "pvremove --force --force --yes {{ item }}"
with_items: "{{ pvs_to_remove.stdout_lines }}"
when:
- pvs_to_remove is defined
- pvs_to_remove.stdout_lines|length > 0