Help with looping lvm filesystem

21 views
Skip to first unread message

Zia

unread,
Oct 17, 2018, 5:25:57 PM10/17/18
to Ansible Project
Hi All,

Looking for some help with looping while creating multiple filesystems with different sizes and mount points.

There are too many volumes, filesystems and mount points that need to be created for one vol group. The file becomes too big so want some help with looping.

test_lvm.yml
- name: Creating new LVM volume group

  sudo: yes

 lvg:

    vg: "{{lvm_volume_group}}"

    pvs: "{{lvm_physical_volumes}}"

    state: present

  when: lvm_create

 

- name: Creating new LVM logical volume

  sudo: yes

  lvol:

    vg: "{{lvm_volume_group}}"

    lv: "{{item.v1}}"

    size: "{{item.s1}}"

    shrink: "{{item.shrink}}"

  with_items: "{{lvm_logical_volumes}}"

  when: lvm_create

 

- name: Creating new filesystem on new LVM logical volume

  sudo: yes

  filesystem:

    fstype: "{{item.filesystem}}"

    dev: "/dev/{{lvm_volume_group}}/{{item.volume}}"

  with_items: "{{lvm_logical_volumes}}"

  when: lvm_create

 

- name: Mounting new filesystem

  sudo: yes

  mount:

    name: "{{item.mount_path}}"

    src: "/dev/{{lvm_volume_group}}/{{item.volume}}"

    fstype: "{{item.filesystem}}"

    opts: "{{item.mount_opts | default('defaults')}}"

    state: "mounted"

  with_items: "{{lvm_logical_volumes}}"

  when: lvm_create



main.yml

lvm_physical_volumes: "/dev/sdc,/dev/sdd"

lvm_volume_group: "dataVG"

lvm_logical_volumes:

  - v1: data1lv

    filesystem: xfs

    m1: "/data1"

    s1: "1"

    mount_opts: noatime

  - v2: data2lv

    filesystem: xfs

    m2: "/data2"

    s1: "1"

    mount_opts: noatime

  - v3: data3lv

    filesystem: xfs

    m3: "/data3"

    s1: "1"

    mount_opts: noatime
Reply all
Reply to author
Forward
0 new messages