---
- name: Validate hypervisor
  hosts: hypervisor
  gather_facts: yes
  any_errors_fatal: true
  tasks:
      - name: calculate needed memory
        include: tasks/calc_needed_memory.yml
        with_dict: "{{ provision.topology.nodes }}"
        loop_control:
            loop_var: node

      - fail:
            msg: "Not enought memory on Hypervisor. Current free memory is {{ ansible_memfree_mb }}MB, required is {{ nodes_memory }}MB. Use `--host-memory-overcommit True` if you want to overcommit memory usage"
        when:
            - nodes_memory|int > ansible_memfree_mb|int
            - not provision.host.memory.overcommit|default('False')
---
- name: Validate hypervisor
  hosts: hypervisor
  gather_facts: yes
  any_errors_fatal: true
  vars:
      memory_buffer: 1.2
  tasks:
      - name: calculate needed memory
        include: tasks/calc_needed_memory.yml
        with_dict: "{{ provision.topology.nodes }}"
        loop_control:
            loop_var: node

      - debug:
            msg: "Current free memory is {{ ansible_memfree_mb }}MB. The required memory for the topology is {{ nodes_memory }}MB and it is more than free memory, but it is under the buffer of 20%."
        when:
            - nodes_memory|int > ansible_memfree_mb|int
            - nodes_memory|int <= ansible_memfree_mb|int * memory_buffer|float

      - fail:
            msg: "Not enought memory on Hypervisor. Current free memory is {{ ansible_memfree_mb }}MB, required is {{ nodes_memory }}MB. Use `--host-memory-overcommit True` if you want to overcommit memory usage"
        when:
            - nodes_memory|int > ansible_memfree_mb|int * memory_buffer|float
            - not provision.host.memory.overcommit|default('False')
Add buffer of 20% for hypervisor free memory check
Add buffer of 20% for hypervisor free memory check

RHOSINFRA-1333: Check/validation now will print
debug/warning message when topology required
memory is more than hypervisor free memory, but
it is not more than 20%.

Change-Id: I00785de2aeaad4dac76b4182aa3ee5ced3a47010
