ansible-playbook动态最大化创建lvm

懂的都懂,上模板

- name: Setup LVM PV VG
  hosts: 192.168.1.2
  #hosts: all
  gather_facts: True
  vars:
    mntp: "/data"
    vgname: "datavg"
    pvname: "/dev/vdb"
    lvname: "datalv"
    vgfree: "2000"
  tasks:
  - name: pvcreate
    shell: "pvcreate {{pvname}}"
    when:
      - ansible_lvm["pvs"]["{{pvname}}"] is not defined

  - name: Check for "{{vgname}}" VG
    shell: "vgcreate {{vgname}} {{pvname}} && sleep 10"
    when:
      - ansible_lvm["vgs"]["{{vgname}}"] is not defined

  - name: gather facts
    setup:

  - name: "Check for {{vgname}} VG Size of {{vgfree}}GiB"
    fail:
      msg: 'vg free_g < {{vgfree}}'
    when:
      - ansible_facts['lvm']['vgs']['{{vgname}}']['free_g'] | int < {{vgfree}}
  
  - name: Create LVM and Filesystem and Mount
    block:
      - name: "Create {{vgfree}}GiB LVM on {{vgname}} VG"
        lvol:
          lv: "{{lvname}}"
          vg: "{{vgname}}"
          size: "+100%FREE"
    #rescue:
    #  - name: Fall back and Create 2000GiB LVM on databin VG
    #    lvol:
    #      size: "+100%FREE"
    #      vg: "{{vgname}}"
    #      lv: "{{lvname}}"
    always:
      - name: Set Filesystem
        filesystem:
          dev: "/dev/{{vgname}}/{{lvname}}"
          fstype: xfs
      - name: Mount LV 
        mount:
          path: "{{mntp}}"
          src: "/dev/{{vgname}}/{{lvname}}"
          fstype: xfs
          state: mounted
此条目发表在linux分类目录。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注