Ansible-分区-格式化-挂载示例

相关模块

  • parted, 用于分区 (需先安装好 parted 工具)
  • filesystem, 用于格式化 (若格式化为 xfs, 需安装 xfsprogs 工具)
  • mount, 用于挂载

各模块的详细用法查看 ansible-doc 命令.

Playbook 示例

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
---
- hosts: Gluster
remote_user: root
gather_facts: no

tasks:
- name: create mount brick1
file:
path: /mnt/point1
state: directory
- name: create mount brick2
file:
path: /mnt/point2
state: directory
- name: install parted
yum:
name: parted
state: present
- name: create part1
parted:
device: /dev/vdb
number: 1
part_end: 5GiB
state: present
- name: create part2
parted:
device: /dev/vdb
number: 2
part_start: 5GiB
part_end: 10GiB
state: present
- name: install xfsprogs
yum:
name: xfsprogs
state: present
- name: format vdb1
filesystem:
dev: /dev/vdb1
fstype: xfs
force: yes
- name: format vdb2
filesystem:
dev: /dev/vdb2
fstype: xfs
force: yes
- name: mount vbd1
mount:
src: /dev/vdb1
path: /mnt/point1
fstype: xfs
state: mounted
- name: mount vbd2
mount:
src: /dev/vdb2
path: /mnt/point2
fstype: xfs
state: mounted
- name: config hosts
lineinfile:
path: /etc/hosts
line: "{{ item }}"
state: present
with_items:
- '10.0.0.21 Gluster-01'
- '10.0.0.22 Gluster-02'
- '10.0.0.23 Gluster-03'

Ansible-分区-格式化-挂载示例
http://example.com/2024/08/13/Ansible-分区-格式化-挂载示例/
作者
Jie
发布于
2024年8月13日
许可协议