使用ansible模組將新磁碟新增至LVM組

使用ansible模組將新磁碟新增至LVM組

團隊,有 lvol 模組,但我很難找到將新設備添加到現有 VG 群組的方法。所以我採取了替代方法來使用 shell 模組並運行 RAW 命令。但有沒有辦法可以使用 ansible 來實現相同的目的?下面是我的程式碼,它透過 4 個步驟運行 4 個任務,並且它們都工作正常。我只需要同等或更好的 ansible 方法。我知道我可以使用 LIST 參數並將其作為單一任務,但我想在輸出中唯一地顯示每個任務,以便觀察到失敗。我可以看到它失敗的地方。

變數.yaml

item: [/dev/sdb, /dev/sde]
- name: "Extend LV Step1 :  PVCreate device {{ item }}"
  shell: |
    pvcreate "{{ item }}"

- name: "Extend LV Step2 :  Extend Volume Group {{ vg_name }} with new device {{ item }}"
  shell: |
     vgextend "{{ vg_name }}" "{{ item }}"

- name: "Extend LV Step3 : Logical Volume Extend"
  shell: |
     lvm lvextend -l +100%FREE "{{ device_prefix }}/{{ vg_name }}/{{ fs_type }}"

- name: "Extend LV Step4: resize2fs"
  shell: |
     resize2fs -p "{{ device_prefix }}/mapper/{{ vg_name }}-{{ fs_type }}"

答案1

我相信,對於 LVM 有 lvol 模組https://docs.ansible.com/ansible/latest/collections/community/general/lvol_module.html(還有其他的,例如lvg)。

相關內容