创建和使用分区
创建一个名为 /home/curtis/ansible/partition.yml 的 playbook:
该palybook包含一个paly,该paly在balancers主机组的主机上运行:
在设备vdb上创建单个主分区,编号为1,大小为1500MiB
使用ext4文件系统格式化该分区
将文件系统永久挂载到/newpart
在设备vdd上创建单个主分区,编号为1,大小为1500MiB
使用ext4文件系统格式化该分区
将文件系统永久挂载到/newpart1
如果无法创建请求的逻辑卷大小,应显示错误信息
Could not create logical volume of that size
,并且应改为使用大小 800 MiB。
如果设备 vdd 不存在,应显示错误信息
Disk does not exist
vim partition.yml
- hosts: balancers
tasks:
- debug:
msg: Disk does not existvdb
when: ansible_devices.vda.size is undefined
failed_when: ansible_devices.vda.size is undefined
- block:
- parted:
device: /dev/vdb
number: 1
state: present
part_end: 10GiB
rescue:
- debug:
msg: Could not create logical volume of that sizevdb
- parted:
device: /dev/vdb
number: 1
state: present
part_end: 800MiB
- filesystem:
fstype: ext4
dev: /dev/vda1
- mount:
path: /newpart
src: /dev/vdb1
state: mounted
fstype: ext4
- debug:
msg: Disk does not exist vdd
when: ansible_devices.vdd.size is undefined
failed_when: ansible_devices.vdd.size is undefined
- block:
- parted:
device: /dev/vdd
number: 1
state: present
part_end: 10GiB
rescue:
- debug:
msg: Could not create logical volume of that size
- parted:
device: /dev/vdd
number: 1
state: present
part_end: 800MiB
- filesystem:
fstype: ext4
dev: /dev/vdd1
- mount:
path: /newpart1
src: /dev/vdd1
state: mounted
fstype: ext4
ansible-playbook partition.yml