使用 Ansible 扩展卷组

问题描述 投票:0回答:1

我试图通过 ansible 通过变量传递 pvname 来扩展 VG,但是我真的不明白为什么不起作用。 下面你可以看到我的代码。

变量文件:

new_disk: 
   - diskname: /dev/sdc
    
pvname: /dev/sdb1, dev/sdc1    
vgname: datavg
lvm_settings:
  - lv_name: datalv  
    lv_size: +100%FREE
    fs_name: ansible_fs_test
   lvpath: /dev/mapper/datavg-datalv
filesystem_type: ext4

任务文件:

 include_vars: "{{ vm_name }}.yml"
    
- name: First disk partition settings
  block:
    - name: Create a new primary partition
      community.general.parted:
        device: "{{ item.diskname }}"
        number: 1
        state: present
      with_items: "{{ new_disk }}"
      register: partition_status
  rescue:
    - name: Debug messages to check the error
      debug:
        msg: "{{ partition_status }}"

- name: Extending the Volume Group
  community.general.lvg:
    vg: "{{ vgname }}"
    pvs: "{{ pvname }}"
    pvresize: yes

下面,您可以看到错误消息:

任务 [resize_fs_linux:扩展卷组] ******************************************** ****************************************************** ****************************************************** **************致命:[10.1.33.225]:失败! => {"changed": false, "msg": "未找到设备 /home/icc-admin/dev/sdc1。"}

您知道为什么不起作用吗? 我非常感谢您的帮助和时间 最好的问候,

linux ansible
1个回答
1
投票

因为它是这样工作的:

变量文件

  diskname: 
      - /dev/sdb
      - /dev/sdc
    
    
    disks_settings:
      - vgname: datavg
        pvname:
          - /dev/sdb1
          - /dev/sdc1
    
    
    lvm_settings:
      - vgname: datavg
        lv_name: datalv  
        lv_size: +100%FREE
        lvpath: /dev/mapper/datavg-datalv
    
    filesystem_type: ext4

任务文件:

 ---
    # tasks file for resize_fs_linux
    - include_vars: "{{ vm_name }}.yml"
        
    - name: First disk partition settings
      block:
        - name: Create a new primary partition
          community.general.parted:
            device: "{{ item }}"
            number: 1
            state: present
          with_items: "{{ diskname }}"
          register: partition_status
          run_once: true
      rescue:
        - name: Debug messages to check the error
          debug:
            msg: "{{ partition_status }}"
    
    - name: Extending the Volume Group
      community.general.lvg:
        vg: "{{ item.vgname }}"
        pvs: "{{ item.pvname }}"
        pvresize: yes
      with_items: "{{ disks_settings }}"

- name: Increasing the filesystems
  community.general.lvol:
    vg: "{{ item.vgname }}"
    lv: "{{ item.lv_name }}"
    size: "{{ item.lv_size }}"
    resizefs: true
  with_items: "{{ lvm_settings }}"
© www.soinside.com 2019 - 2024. All rights reserved.