Convert available and minimum disk sizes to bytes.

Previously the check-requirements role would assume GB as the unit
of space when gathering disk sizes from ansible_devices. With
drives larger than 1 TB ansible_devices reports the size as a
float. This converts all disk sizes to bytes for consistency within
the comparisons regardless of the size of the disk.

Change-Id: I07b81a8a35197f73cd338fa02cb7b112df15a012
Closes-Bug: 1536726
(cherry picked from commit 85aad72a91)
This commit is contained in:
d34dh0r53 2016-01-21 15:44:01 -06:00
parent 9354f65cf3
commit aac713dcb0
1 changed files with 34 additions and 4 deletions

View File

@ -21,7 +21,7 @@
- name: Identify the space available in /
shell: |
df -BG / | awk '/^[^Filesystem]/ {print $4}' | sed 's/G//'
df -BK / | awk '/^[^Filesystem]/ {print $4}' | sed 's/K//'
when:
- bootstrap_host_data_disk_device is not defined
changed_when: false
@ -29,10 +29,41 @@
tags:
- check-disk-size
- name: Set root disk facts
set_fact:
host_root_space_available: "{{ ( root_space_available.stdout | int) * 1024 | int }}"
when:
- bootstrap_host_data_disk_device is not defined
tags:
- check-disk-size
- name: Set data disk facts
set_fact:
host_data_disk_sectors: "{{ (ansible_devices[bootstrap_host_data_disk_device]['sectors'] | int) }}"
host_data_disk_sectorsize: "{{ (ansible_devices[bootstrap_host_data_disk_device]['sectorsize'] | int) }}"
when:
- bootstrap_host_data_disk_device is defined
tags:
- check-disk-size
- name: Calculate data disk size
set_fact:
host_data_disk_size: "{{ ((host_data_disk_sectors | int) * (host_data_disk_sectorsize | int)) | int }}"
when:
- bootstrap_host_data_disk_device is defined
tags:
- check-disk-size
- name: Set min size fact
set_fact:
host_data_disk_min_size: "{{ ((bootstrap_host_data_disk_min_size | int) * 1024**3) | int }}"
tags:
- check-disk-size
- name: Fail if there is not enough space available in /
assert:
that: |
root_space_available.stdout | int >= (bootstrap_host_data_disk_min_size * 0.75) | int
(host_root_space_available | int) >= ((host_data_disk_min_size | int) * 0.75)
when:
- bootstrap_host_data_disk_device is not defined
tags:
@ -41,8 +72,7 @@
- name: Fail if there is not enough disk space available (disk specified)
assert:
that: |
(ansible_devices[bootstrap_host_data_disk_device]['size'] | replace(' GB','')) | int
>= bootstrap_host_data_disk_min_size | int
(host_data_disk_size | int) >= (host_data_disk_min_size | int)
when:
- bootstrap_host_data_disk_device is defined
tags: