大网数据广告活动
服务器运维问答

Resize LVM volume with Ansible

· 52CE 我爱测

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…

问题原文

原帖链接 · Jared · CC BY-SA 4.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 error 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 doing wrong? Am I missing some other required argument perhaps?

I'm using Ansible 2.9.10. Thanks.

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-11-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。