Bootstrap FreeKB - Ansible - ansible_lvm fact
Ansible - ansible_lvm fact

Updated:   |  Ansible articles

You may be able to use the ansible_lvm fact to return LVM (logical volume manager) information.

---
- hosts: all
  tasks:
  - debug:
      var: ansible_lvm
...

 

However, don't be surprised if the ansible_lvm fact returns VARIABLE IS NOT DEFINED!

ok: [server1.example.com] => {
    "ansible_lvm": "VARIABLE IS NOT DEFINED!"
}

 

Best I can tell, there are 2 things that need to be in place in order for the ansible_lvm fact to return LVM (logical volume manager) information.

  1. The playbook must be run as root or using become_user: root
  2. The LVM utiltiies package such as lvm-utils must be installed on the target system

So, you can probably try something like this. Check out my article Manage packages using the package module for more details on using the package module to determine if the LVM utilties package is installed and why I'm using json_query to determine if the package is installed.

---
- hosts: all
  tasks:
  - name: determine if the LVM utils package is installed
    become: yes
    become_user: root
    package:
      list: lvm-utils
    register: lvmutils

  - debug:
      var: ansible_lvm
    become: yes
    become_user: root
    with_items: "{{ out | json_query('results[0].yumstate') }}"
    when: item == 'installed'
...

 

If you are lucky enough to have the ansible_lvm fact capture LVM facts, something like this should be returned.

  • lvs = logical volume size (like the lvdisplay command)
  • pvs = physical group size (like the pvdisplay command)
  • vgs = volume group size (like the vgdisplay command)
ok: [lab1.software.eng.us] => {
    "ansible_lvm": {
        "lvs": {
            "root": {
                "size_g": "7.00",
                "vg": "fedora_fedora"
            }
        },
        "pvs": {
            "/dev/sda2": {
                "free_g": "0",
                "size_g": "7.00",
                "vg": "fedora_fedora"
            }
        },
        "vgs": {
            "fedora_fedora": {
                "free_g": "0",
                "num_lvs": "1",
                "num_pvs": "1",
                "size_g": "7.00"
            }
        }
    }
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter d9eef3 in the box below so that we can be sure you are a human.