将磁盘sdb格式化为xfs文件系统:
- name: Broker server - make filesystem
filesystem:
fstype: xfs
dev: /dev/sdb
opts: -n ftype=1 -L "data"
when: ('broker_az1' in group_names) or ('broker_az2' in group_names)
创建要挂载的文件系统目录/data
:
- name: Broker server - make datadir
file:
path: /data
state: directory
when: ('broker_az1' in group_names) or ('broker_az2' in group_names)
获取磁盘sdb的UUID并保存到变量中:
- name: Broker server - get sdb uuid
shell: 'blkid -s UUID /dev/sdb | cut -d " " -f2'
register: uuid_sdb
when: ('broker_az1' in group_names) or ('broker_az2' in group_names)
- name: check uuid_sdb variable
debug:
msg: "uuid: {{uuid_sdb.stdout}}"
when: ('broker_az1' in group_names) or ('broker_az2' in group_names)
在/etc/fstab
中配置文件系统开机自动挂载:
- name: Broker server - auto-mount config in /etc/fstab
lineinfile:
line: "{{uuid_sdb.stdout}} /data xfs defaults 0 0"
state: present
path: /etc/fstab
when: ('broker_az1' in group_names) or ('broker_az2' in group_names)
挂载文件系统并检查挂载情况:
- name: Broker server - mount datadir & display info
shell: "mount -a && df -h"
when: ('broker_az1' in group_names) or ('broker_az2' in group_names)
利用磁盘vdb创建VG(此过程中会自动创建PV):
- name: Other servers - create vg_tdmq using /dev/vdb
lvg:
vg: vg_tdmq
state: present
pvs: /dev/vdb
when: ('broker_az1' not in group_names) and ('broker_az2' not in group_names) and ('bookie_az1' not in group_names) and ('bookie_az2' not in group_names)
利用创建好的VG来创建LV:
- name: Other servers - create LV data using vg_tdmq
lvol:
vg: vg_tdmq
lv: lv_data
size: 100%FREE
state: present
when: ('broker_az1' not in group_names) and ('broker_az2' not in group_names) and ('bookie_az1' not in group_names) and ('bookie_az2' not in group_names)
将创建好的LV格式化为xfs文件系统:
- name: Other servers - make filesystem
filesystem:
fstype: xfs
dev: /dev/vg_tdmq/lv_data
opts: -n ftype=1 -L "data"
when: ('broker_az1' not in group_names) and ('broker_az2' not in group_names) and ('bookie_az1' not in group_names) and ('bookie_az2' not in group_names)
创建要挂载的文件系统目录/data
:
- name: Other servers - make datadir
file:
path: /data
state: directory
when: ('broker_az1' not in group_names) and ('broker_az2' not in group_names) and ('bookie_az1' not in group_names) and ('bookie_az2' not in group_names)
获取lv_data
的UUID并保存到变量中:
- name: Other servers - get vdb uuid
shell: 'blkid -s UUID /dev/mapper/vg_tdmq-lv_data | cut -d " " -f2'
register: uuid_vdb_lvdata
when: ('broker_az1' not in group_names) and ('broker_az2' not in group_names) and ('bookie_az1' not in group_names) and ('bookie_az2' not in group_names)
在/etc/fstab
中配置文件系统开机自动挂载:
- name: Other servers - auto-mount config in /etc/fstab
lineinfile:
line: "{{uuid_vdb_lvdata.stdout}} /data xfs defaults 0 0"
state: present
path: /etc/fstab
when: ('broker_az1' not in group_names) and ('broker_az2' not in group_names) and ('bookie_az1' not in group_names) and ('bookie_az2' not in group_names)
挂载文件系统并检查挂载情况:
- name: Other servers - mount datadir & display info
shell: "mount -a && df -h"
when: ('broker_az1' not in group_names) and ('broker_az2' not in group_names) and ('bookie_az1' not in group_names) and ('bookie_az2' not in group_names)