0

Short version: how do you resize/extend a logical volume with ansible?

It includes built-in support for managing both physical volumes and volume groups and logical volumes.

Based on the following info from that second link, I'm assuming it's capable of extending logical volumes:

  1. "This module creates, removes or resizes logical volumes."
  2. resizefs: Resize the underlying filesystem together with the logical volume.

Plus, the following example in the documentation:

- name: Extend the logical volume to take all remaining space of the PVs and resize the underlying filesystem
  lvol:
    vg: firefly
    lv: test
    size: 100%PVS
    resizefs: true

However, my attempts to resize result in failure. I have these vars defined:

lvm_group: vg00

lvm_volumes:
  - name: /dev/mapper/vg00-lv_home
    size: 5G

and I'm running this task:

- name: configure LVM logical volumes
  lvol:
    vg: "{{ lvm_group }}"
    lv: "{{ item.name }}"
    size: "{{ item.size }}"
    resizefs: yes
  with_items:
   "{{ lvm_volumes }}"

Note: I've tried with resizefs set to both yes (as in the documentation) and true (as in the example).

However, I get this failure when running:

failed: [169.198.54.175] (item={u'name': u'/dev/mapper/vg00-lv_home', u'size': u'5G'}) => changed=false
  ansible_loop_var: item
  err: |2-
      Logical Volume "lv_home" already exists in volume group "vg00"
  item:
    name: /dev/mapper/vg00-lv_home
    size: 5G
  msg: Creating logical volume '/dev/mapper/vg00-lv_home' failed
  rc: 5

Can anyone help me understand what I'm going wrong? Am I missing some other required argument perhaps?

I'm using ansible 2.9.10. Thanks.

  • Please show the actual tasks you tried to run along with the items you passed to it. – Michael Hampton Nov 17 '20 at 5:27
  • I did. See the vars and task I included as code, which you'll note also matches the variables mentioned in the example output. If you're looking for something different, would you please be more specific? – Jared Nov 17 '20 at 5:55
  • Oh you're right, not sure how I missed those. I think including the example is confusing. – Michael Hampton Nov 17 '20 at 6:32
  • 1
    I suspect you've found a subtle issue in this Ansible module. Try passing it the LV name that it wants, rather than the full path to the block device. – Michael Hampton Nov 17 '20 at 6:36
  • man, yes! That did it. I didn't think to try that because lvdisplay demands the full path. But yep, just specifying the name did the trick. Would you mind posting that as an answer so I can accept it? – Jared Nov 17 '20 at 7:14
1

I think the Ansible lvol module wants just the logical volume name as lv, but you have passed it the full path to the block device. Try passing it the LV name instead.

  • Confirmed. Thanks, Michael - appreciate the quick help. – Jared Nov 17 '20 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.