-
Notifications
You must be signed in to change notification settings - Fork 117
/
fdisk.yml
110 lines (109 loc) · 3.15 KB
/
fdisk.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
---
- name: "格式化挂载磁盘"
hosts: all
vars:
disk: sdb
dir: /data
num: 1
tasks:
- name: set partation variable
set_fact:
partation: "{{ disk }}{{ num }}"
- stat:
path: "/dev/{{ partation }}"
register: disk_stat
tags: fdisk
- name: "创建/dev/{{ disk }}分区"
when: not disk_stat.stat.exists
parted:
device: "/dev/{{ disk }}"
number: 1
part_type: primary
part_start: 0%
part_end: 100%
label: gpt
state: present
tags: fdisk
- name: "disk"
debug:
msg: "即将格式化的磁盘分区是/dev/{{ partation }}"
tags: fdisk
- name: "格式化/dev/{{ partation }}分区"
when: not disk_stat.stat.exists
filesystem:
dev: "/dev/{{ partation }}"
force: yes
fstype: xfs
tags: fdisk
- name: 重新获取facter
setup:
gather_subset:
- '!all'
- '!any'
- hardware
tags: fdisk
- name: 获取/dev/{{ partation }}的UUID
set_fact:
device_uuid: "{{ item.value }}"
with_dict:
- "{{ ansible_device_links.uuids }}"
when: item.key == (partation)
tags: fdisk
- name: "挂载/dev/{{ partation }}分区到{{ dir }}目录"
mount:
path: "{{ dir }}"
src: "UUID={{device_uuid[0]}}"
fstype: xfs
opts: defaults,noatime,nodiratime,pquota
state: mounted
tags: fdisk
- name: "创建etcd目录"
file:
path: "{{ item.line }}"
owner: root
group: root
mode: 0755
state: directory
with_items:
- {line: "{{ dir }}/containers/etcd"}
- {line: "/var/lib/etcd"}
when: inventory_hostname in groups['etcd']
tags: bind_dir
- name: "绑定etcd数据目录到{{ dir }}目录"
mount:
path: "/var/lib/etcd"
src: "{{ dir }}/containers/etcd"
fstype: none
opts: defaults,bind
state: mounted
when: inventory_hostname in groups['etcd']
tags: bind_dir
- name: "创建worker目录"
file:
path: "{{ item.line }}"
owner: root
group: root
mode: 0755
state: directory
with_items:
- {line: "{{ dir }}/containers/kubelet"}
- {line: "{{ dir }}/containers/containerd"}
- {line: "{{ dir }}/containers/log"}
- {line: "/var/lib/kubelet"}
- {line: "/var/lib/containerd"}
- {line: "/var/log/pods"}
when: (inventory_hostname in groups['master'] or inventory_hostname in groups['worker'])
tags: bind_dir
- name: "绑定worker数据目录到{{ dir }}目录"
mount:
path: "{{ item.path }}"
src: "{{ item.src }}"
fstype: none
opts: defaults,bind
state: mounted
with_items:
- {src: "{{ dir }}/containers/kubelet", path: "/var/lib/kubelet"}
- {src: "{{ dir }}/containers/containerd", path: "/var/lib/containerd"}
- {src: "{{ dir }}/containers/log", path: "/var/log/pods"}
when: (inventory_hostname in groups['master'] or inventory_hostname in groups['worker'])
tags: bind_dir