ansible-aix / ansible-power-aix

Developer contributions for Ansible Automation on Power
GNU General Public License v3.0
3 stars 1 forks source link

lvm_facts modules #82

Open dberg1 opened 3 years ago

dberg1 commented 3 years ago

lslv / lsvg / lspv commands

Here is an additional code snip where I calculate free space in uservg.

(1a) Check if there is at least 6GB of free space in uservg

- name: Check uservg for 6GB of free space using shell command
  shell: lsvg uservg | grep "PP SIZE" | awk '{print $6}'
  register: ppsize_info
  when: uservg_info.stdout == "uservg"

# Print the free_pps
#    - debug:
#        var: ppsize_info.stdout

# Parsing through Variable Dictionary to get free_pps and pps_size
- name: get free_pps and pps_size in uservg
  no_log: True
  set_fact:
    freepps: "{{ freepps|int + item.free_pps|int }}"
    ppsize: "{{ ppsize_info.stdout }}"
  loop: "{{ansible_vgs.uservg}}"

- name: total free space in uservg
  set_fact:
    totalfree: "{{ (freepps|int * ppsize|int) / ddd|int }}"

# Print Total free space in uservg
- debug:
    var: totalfree

- fail:
    msg: USERVG does not have the minimum free space required !.
  when: totalfree | int < 6 and uservg_exists == True
dberg1 commented 3 years ago

Just noticed that VGs, mounts, devices, network interfaces and CPUs are already in ansible_facts: See https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/facts/hardware/aix.py

"ansible_facts": {
        "mounts": [
            {
                "block_available": 41685,
                "block_size": 4096,
                "block_total": 98304,
                "block_used": 56619,
                "device": "/dev/hd4",
                "fstype": "jfs2",
                "inode_available": 40166,
                "inode_total": 52669,
                "inode_used": 12503,
                "mount": "/",
                "options": "rw,log=/dev/hd8",
                "size_available": 170741760,
                "size_total": 402653184,
                "time": "Jul 12 12:18"
            },
...
        "vgs": {
            "rootvg": [
                {
                    "free_pps": "0",
                    "pp_size": "64 megabyte(s)",
                    "pv_name": "hdisk0",
                    "pv_state": "active",
                    "total_pps": "639"
                },
                {
                    "free_pps": "435",
                    "pp_size": "64 megabyte(s)",
                    "pv_name": "hdisk1",
                    "pv_state": "active",
                    "total_pps": "625"
                }
            ]
        },