Sonntag, 15. Juli 2018

Resize a logical volume with Ansible with checks before

Situation:
My challenge is to check my nodes if the root directory has enough space and if not check if the volume group has also enough space to resize the logical volume.

Here is my Ansible code. I'm sure it's not perfect, but it works :-)

# Check nodes before Upgrade Cluster
---
- hosts: all
  become: True
  tasks:

    - name: Test disk space available
      assert:
        that:
         - item.mount != '/' or {{ item.mount == '/' and \
                   item.size_available > (item.size_total) }}
      with_items: '{{ ansible_mounts }}'
      ignore_errors: yes
      register: disk_free

    - name: Check VG for enough space
      assert:
        that:
          - item.key != '{{ VG }}' or {{ item.key == '{{ VG }}' \
                   and item.value.free_g > 1.00 }}
      with_dict: '{{ ansible_lvm.vgs }}'
      register: vg_free
      ignore_errors: yes
      when: disk_free is failed

    - name: resize lvROOT
      shell: lvresize -L +1G /dev/VG/lv && xfs_growfs /

      when: vg_free is succeeded

Keine Kommentare:

Kommentar veröffentlichen