实验目标
- 在自建环境中能够测试RHCE磁盘管理题目
- 在部分主机上做特殊处理,使得自己练习环境与实际环境相似
实验环境
ansible配置文件
[defaults]
inventory=./inventory
remote_user=rhce
ask_pass=false
roles_path=./roles
host_key_checking=false
[privilege_escalation]
become=true
become_user=root
become_method=sudo
become_ask_pass=false
清单主机文件
[dev]
servera
[test]
serverb
[prod]
serverc
serverd
[balancers]
servere
[webservers:children]
prod
脚本文件
---
- name: create resreach lvm
hosts: all
tasks:
- name: show disk message
shell: 'lsblk'
register: disk_info
- name: create vgm for dev,test
parted:
device: /dev/sdb
number: 1
state: present
part_start: 1MiB
part_end: 2000MiB
resize: true
when: 'sdb' in {{ disk_info }}
register: vgm_info
when: inventory_hostname in {{ item }}
with_items:
- groups['dev']
- groups['test']
- name: create vgm for prod
parted:
device: /dev/sdb
number: 1
state: present
part_end: "20%"
resize: true
flags: [ lvm ]
when: inventory_hostname in groups['prod']
# 在已分配的pv中创建名为research的vg
- name: create vg research 100%
lvg:
vg: research
pvs: /dev/sdb1
pesize: 16
- block:
- name: create lvm 1500M
lvol:
vg: research
lv: data
size: 1500
register: lvm_info
rescue:
- name: show vgm_info
debug:
msg: "Could not create logical volume of that size"
- name: create lvm 800M
lvol:
vg: research
lv: data
size: 800
- name: show device size
debug:
msg: "{{ ansible_devices.sdb.size }}"
always:
- name: create filesystem
filesystem:
fstype: xfs
dev: /dev/research/data
- name: remove lvm data
shell: "lvremove -y /dev/research/data"