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
This commit is contained in:
parent
2b6c9c39fa
commit
ef1a45fc05
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
- name: Identify the space available in /
|
- name: Identify the space available in /
|
||||||
shell: |
|
shell: |
|
||||||
df -BG / | awk '/^[^Filesystem]/ {print $4}' | sed 's/G//'
|
df -BK / | awk '/^[^Filesystem]/ {print $4}' | sed 's/K//'
|
||||||
when:
|
when:
|
||||||
- bootstrap_host_data_disk_device is not defined
|
- bootstrap_host_data_disk_device is not defined
|
||||||
changed_when: false
|
changed_when: false
|
||||||
@ -29,10 +29,44 @@
|
|||||||
tags:
|
tags:
|
||||||
- check-disk-size
|
- check-disk-size
|
||||||
|
|
||||||
|
# Convert root_space_available to bytes.
|
||||||
|
- name: Set root disk facts
|
||||||
|
set_fact:
|
||||||
|
host_root_space_available_bytes: "{{ ( 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
|
||||||
|
|
||||||
|
# Calculate the size of the bootstrap_host_data_disk_device by muliplying sectors with sectorsize.
|
||||||
|
- name: Calculate data disk size
|
||||||
|
set_fact:
|
||||||
|
host_data_disk_size_bytes: "{{ ((host_data_disk_sectors | int) * (host_data_disk_sectorsize | int)) | int }}"
|
||||||
|
when:
|
||||||
|
- bootstrap_host_data_disk_device is defined
|
||||||
|
tags:
|
||||||
|
- check-disk-size
|
||||||
|
|
||||||
|
# Convert bootstrap_host_data_disk_min_size to bytes.
|
||||||
|
- name: Set min size fact
|
||||||
|
set_fact:
|
||||||
|
host_data_disk_min_size_bytes: "{{ ((bootstrap_host_data_disk_min_size | int) * 1024**3) | int }}"
|
||||||
|
tags:
|
||||||
|
- check-disk-size
|
||||||
|
|
||||||
- name: Fail if there is not enough space available in /
|
- name: Fail if there is not enough space available in /
|
||||||
assert:
|
assert:
|
||||||
that: |
|
that: |
|
||||||
root_space_available.stdout | int >= (bootstrap_host_data_disk_min_size * 0.75) | int
|
(host_root_space_available_bytes | int) >= ((host_data_disk_min_size_bytes | int) * 0.75)
|
||||||
when:
|
when:
|
||||||
- bootstrap_host_data_disk_device is not defined
|
- bootstrap_host_data_disk_device is not defined
|
||||||
tags:
|
tags:
|
||||||
@ -41,8 +75,7 @@
|
|||||||
- name: Fail if there is not enough disk space available (disk specified)
|
- name: Fail if there is not enough disk space available (disk specified)
|
||||||
assert:
|
assert:
|
||||||
that: |
|
that: |
|
||||||
(ansible_devices[bootstrap_host_data_disk_device]['size'] | replace(' GB','')) | int
|
(host_data_disk_size_bytes | int) >= (host_data_disk_min_size_bytes | int)
|
||||||
>= bootstrap_host_data_disk_min_size | int
|
|
||||||
when:
|
when:
|
||||||
- bootstrap_host_data_disk_device is defined
|
- bootstrap_host_data_disk_device is defined
|
||||||
tags:
|
tags:
|
||||||
|
Loading…
Reference in New Issue
Block a user