-
Notifications
You must be signed in to change notification settings - Fork 40
/
arrays.yml
156 lines (138 loc) · 4.82 KB
/
arrays.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
---
# Checking for any existing raid arrays
- name: arrays | Checking Status Of Array(s)
shell: "cat /proc/mdstat | grep {{ item.name }}"
register: "array_check"
changed_when: false
failed_when: false
with_items: '{{ mdadm_arrays }}'
check_mode: no
# Creating raid arrays
# We pass yes in order to accept any questions prompted for yes|no
- name: arrays | Creating Array(s)
shell: "yes | mdadm --create /dev/{{ item.name }} --level={{ item.level }} {% if item.level != 1 %}--chunk={{item.chunk_size|default('512K')}}{% endif %} --metadata={{ item.raid_metadata_version | default(1.2) }} --raid-devices={{ item.devices|count }} {{ item.devices| join (' ') }}"
register: "array_created"
with_items: '{{ mdadm_arrays }}'
when: >
item.state|lower == "present" and
array_check.results[0].rc != 0
# Updates initramfs archives in /boot
- name: arrays | Updating Initramfs
command: "{{ update_initramfs }}"
when: array_created.changed
# Capture the raid array details to append to mdadm.conf
# in order to persist between reboots
- name: arrays | Capturing Array Details
command: "mdadm --detail --scan"
register: "array_details"
changed_when: false
# Creating raid arrays filesystem
- name: arrays | Creating Array(s) Filesystem
filesystem:
fstype: "{{ item.filesystem }}"
opts: "{{ item.filesystem_opts | default(omit) }}"
dev: "/dev/{{ item.name }}"
with_items: '{{ mdadm_arrays }}'
when:
- item.state|lower == "present"
- item.filesystem is defined
# Mounting raid arrays
- name: arrays | Mounting Array(s)
mount:
name: "{{ item.mountpoint }}"
src: "/dev/{{ item.name }}"
fstype: "{{ item.filesystem }}"
state: "mounted"
opts: "{{ item.opts | default(omit) }}"
with_items: '{{ mdadm_arrays }}'
when:
- item.state|lower == "present"
- item.filesystem is defined
- item.mountpoint is defined
# Unmounting raid arrays in preparation of destroying
- name: arrays | Unmounting Array(s)
mount:
name: "{{ item.mountpoint }}"
src: "/dev/{{ item.name }}"
state: "unmounted"
with_items: '{{ mdadm_arrays }}'
when:
- item.state|lower == "absent"
- item.mountpoint is defined
# Stopping raid arrays in preparation of destroying
- name: arrays | Stopping Array(s)
command: "mdadm --stop /dev/{{ item.name }}"
register: "array_stopped"
with_items: '{{ mdadm_arrays }}'
when: >
item.state|lower == "absent" and
array_check.results[0].rc == 0
# Removing raid arrays
- name: arrays | Removing Array(s)
command: "mdadm --remove /dev/{{ item.name }}"
register: "array_removed"
with_items: '{{ mdadm_arrays }}'
when: >
item.state|lower == "absent" and
array_check.results[0].rc == 0
# Zeroing out the disk devices which were part of the raid array
- name: arrays | Zeroing Out Array Devices
command: "mdadm --zero-superblock {{ item.1 }}"
with_subelements:
- '{{ mdadm_arrays }}'
- devices
when: >
item.0.state|lower == "absent" and
array_check.results[0].rc == 0 and
array_removed.changed
# Wiping out the disk devices which were part of the raid array
- name: arrays | Wiping Out Array Devices
command: "wipefs -af {{ item.1 }}"
with_subelements:
- '{{ mdadm_arrays }}'
- devices
when: >
item.0.state|lower == "absent" and
array_check.results[0].rc == 0 and
array_removed.changed
- name: arrays | Ensure {{ mdadm_conf }}'s directory exists
file:
path: "{{ mdadm_conf_path }}"
state: directory
when: mdadm_conf_path is defined
- name: arrays | Ensure {{ mdadm_conf }} file exists
copy:
content: ""
dest: "{{ mdadm_conf }}"
force: no
# Updating mdadm.conf in order to persist between reboots
- name: arrays | Updating {{ mdadm_conf }}
lineinfile:
dest: "{{ mdadm_conf }}"
regexp: "^{{ item }}"
line: "{{ item }}"
state: "present"
with_items: '{{ array_details.stdout_lines }}'
when: array_created.changed
# Updating mdadm.conf in order to not persist between reboots
- name: arrays | Updating {{ mdadm_conf }}
lineinfile:
dest: "{{ mdadm_conf }}"
regexp: "^ARRAY /dev/{{ item.name }}"
line: "ARRAY /dev/{{ item.name }}"
state: "absent"
with_items: '{{ mdadm_arrays }}'
when: >
item.state == "absent"
# Updates initramfs archives in /boot
- name: arrays | Updating Initramfs
command: "{{ update_initramfs }}"
when: array_removed.changed and ansible_facts.os_family == "Debian"
# Updates initramfs archives in /boot
- name: arrays | Updating Initramfs
command: "mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-backup.img"
when: array_removed.changed and ansible_facts.os_family == "RedHat"
# Updates initramfs archives in /boot
- name: arrays | Updating Initramfs
command: "dracut /boot/initramfs-$(uname -r).img $(uname -r)"
when: array_removed.changed and ansible_facts.os_family == "RedHat"