---
- hosts: undercloud
  vars:
    metadata:
      name: Verify undercloud fits the disk space requirements
      description: >
        Make sure that the root partition on the undercloud node is large enough.

        We first check for an explicit `/var` mount point since that's
        where we store logs and images and if it doesn't exist, we
        fall back to `/`.

        http://tripleo.org/environments/environments.html#id5
      groups:
        - prep
        - pre-introspection
    min_undercloud_disk_gb: 60
  tasks:
  - name: Verify disk space in /var (if it exists)
    # NOTE(shadower): 1073741824 == (1024 * 1024 * 1024), i.e. bytes
    # in a gigabyte
    fail: msg="The available space on the /var partition is {{ item.size_available|int / 1073741824 }} GB, but it should be at least {{ min_undercloud_disk_gb }} GB."
    with_items: "{{ ansible_mounts }}"
    when: "'/var' == '{{ item.mount }}'"
    failed_when: "{{ min_undercloud_disk_gb|int * 1073741824 }} >= {{ item.size_available|int }}"
    # Notify the next task that we've checked /var (and that it exists)
    changed_when: True
    register: previous

  - name: Verify root disk space
    fail: msg="The available space on the root partition is {{ item.size_available|int / 1073741824 }} GB, but it should be at least {{ min_undercloud_disk_gb }} GB."
    with_items: "{{ ansible_mounts }}"
    # Only run this when /var doesn't exist
    when: "{{ not previous.changed }} and '/' == '{{ item.mount }}'"
    failed_when: "{{ min_undercloud_disk_gb|int * 1073741824 }} >= {{ item.size_available|int }}"
