Ansiable-ploybook LVM
Ansible 配置文件修改
位置在:vim /etc/ansible/ansible.cfg
host_key_checking = False # 首次连接是否需要检查key认证,建议设为False
主机清单编写
[master] 192.168.1.80 ansible_connection=local 【可以本地执行】 [master:vars] hostanme=master01 [client] 192.168.1.81hostname=node01 192.168.1.82 hostname=node02 [client:vars] ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123456 [redis:children] master client
编写vars_file
[root@master01 lvm]# vim storage_vars.yml
--- partitions: - number: 1 start: 1MiB end: 1000GiB # - number: 2 # start: 1000GiB # end: 2000GiB volumegroups: - vg: vgdata pvs: /dev/sdb1 # - vg: vgdata1 # pvs: /dev/sdb2 # pe: 4 logicalvolumes: - vg: vgdata lv: lv01 size: 100%VG name: lv01 # - name: lv02 # vg: /dev/sdb2 # lv: lv02 # size: 100%VG filesystem: - fstype: xfs dev: /dev/vgdata/lv01 # - fstype: xfs # dev: /dev/vgdata/lv02 mountargs: - path: /data src: /dev/vgdata/lv01 # - patg: /ww # src: /dev/vgdata/lv02
编写LVM剧本
[root@master01 lvm]# cat my_disk.yaml
--- - hosts: total vars_files: - storage_vars.yml tasks: - shell: test -b /dev/sdb ##shell模块判断磁盘设备是否存在 register: result ignore_errors: True - debug: msg: "/dev/sdb not exists" ##不存在报错 when: result.rc != 0 ##磁盘分区(parted模块) - name: Create a new primary partition with a size of 1000GiB parted: device: /dev/sdb number: "{{ item.number }}" part_start: "{{ item.start }}" part_end: "{{ item.end }}" label: gpt state: present flags: [ lvm ] loop: "{{ partitions }}" ##创建PV - name: Create a volume group on top of /dev/sdb1 with physical extent size = 4MB lvg: vg: "{{ item.vg }}" pvs: "{{ item.pvs }}" loop: "{{ volumegroups }}" ##创建LV - name: create a logical volume #创建lv lvol: vg: "{{ item.vg }}" lv: "{{ item.lv }}" size: "{{ item.size }}" resizefs: true #可以扩展 force: yes #如果有数据,强制创建 state: present loop: "{{ logicalvolumes }}" when: item.name not in ansible_lvm["lvs"] ##磁盘格式化(filesystem模块) - name: Create a xfs filesystem on lvm filesystem: fstype: "{{ item.fstype }}" dev: "{{ item.dev }}" loop: "{{ filesystem }}" ##挂载LV - name: Mount up device mount: path: "{{ item.path }}" ##挂在点 src: "{{ item.src }}" ##挂在的设备 fstype: xfs ##挂在系统 opts: defaults state: mounted loop: "{{ mountargs }}"
继续阅读

我的微信
这是我的微信扫一扫
评论