RHCE之路–08创建和使用分区
1. 考题
创建一个名为 /home/student/ansible/partition.yml 的 playbook ,它将在所有受管节点上创建分区:
- 在vdb 创建一个1500M 主分区,分区号1 ,并格式化ext4
- dev 组将分区永久挂载到/data如果磁盘空间不够,
- 给出提示信息Could not create partition of that size
- 创建800MiB 分区
- 如果 vdb不存在,则给出提示信息this disk is not exist
2. 解题
2.1 编辑yml
vi /home/student/ansible/partition.yml
---
- hosts: all
tasks:
- block:
- name: create 1500M
parted:
device: /dev/vdb
number: 1
state: present
part_end: 1500MiB
when: ansible_devices.vdb is defined
rescue:
- name: not enough 1500m
debug:
msg: "Could not create partition of that size"
when: ansible_devices.vdb is defined
- name: create 800m
parted:
device: /dev/vdb
number: 1
state: present
part_end: 800MiB
when: ansible_devices.vdb is defined
always:
- name: format
filesystem:
fstype: ext4
dev: /dev/vdb1
when: ansible_devices.vdb is defined
- name: mkdir
file:
state: directory
path: /data
when: ansible_devices.vdb is defined
- name: mount disk
mount:
path: /data
src: /dev/vdb1
fstype: ext4
state: mounted
when: ansible_devices.vdb is defined
- name: vdb is not defined
debug:
msg: "this disk is not exist"
when: ansible_devices.vdb is not defined
2.2 执行yml
ansible-playbook /home/student/ansible/partition.yml
3. 确认本题是否成功
没有错误提示
ansible all -a 'lvs'