1.创建分区
---
- name: create parted
hosts: shr
gather_facts: false
tasks:
- name: create directory
file:
path: /mnt/xp
state: directory
- name: Create partition
parted:
device: /dev/xvdb
number: 1
#label: gpt
part_start: 0%
part_end: 100%
state: present
2.格式化文件系统
- name: Format File System
filesystem:
dev: /dev/xvdb1
fstype: ext4
3.获取磁盘的uuid
- name: Obtain the uuid of the disk
shell: 'blkid -s UUID -o value /dev/xvdb1'
register: uuid_num
4.更新 fstab,并插入在以 uuid 开头的行的后面
- name: update /etc/fstab
lineinfile:
path: /etc/fstab
insertafter: '^UUID='
line: "UUID={{ uuid_num.stdout }} /mnt/xp ext4 defaults 0 0"
state: present
5.立即挂载
- name: Write to/etc/fstab
mount:
path: /mnt/xp
src: "UUID={{ uuid_num.stdout }}"
fstype: ext4
state: mounted