Skip to content
Snippets Groups Projects
Commit 44503341 authored by McConahy, Renee Margaret's avatar McConahy, Renee Margaret
Browse files

roles/minimum_memory: Correct calculation errors.

When it already exists, the swap file managed by the role must be
excluded from the sum of memory and swap used to calculate the size of
said file.

The size of the swap file's header ought to be included in the
calculation; otherwise, the file will be slightly undersized, and the
role will re-create it at every invocation.
parent 73852ccb
No related branches found
No related tags found
No related merge requests found
......@@ -16,10 +16,15 @@
command: swapoff -- {{ swapfile_name | quote }}
when: not r.rc
- name: "Update fact: ansible_swaptotal_mb."
setup:
filter: ansible_swaptotal_mb
- name: Create swapfile.
command: dd if=/dev/zero of={{ swapfile_name | quote }} bs=1024k
count={{ minimum_memory_mb - ansible_memtotal_mb -
ansible_swaptotal_mb }}
# The swapfile's header takes up 4 KiB.
command: dd if=/dev/zero of={{ swapfile_name | quote }} bs=1024
count={{ (minimum_memory_mb - ansible_memtotal_mb -
ansible_swaptotal_mb) * 1024 + 4 }}
- name: Set swapfile permissions.
file:
......@@ -39,4 +44,12 @@
- name: Enable swapping for file.
command: swapon -- {{ swapfile_name | quote }}
- name: "Update fact: ansible_swaptotal_mb."
setup:
filter: ansible_swaptotal_mb
# Nota bene: No tasks belong below this point in the block. The "when"
# clause is re-evaluated before each task, and the setup call above this
# will make it evaluate to false.
when: ansible_memtotal_mb + ansible_swaptotal_mb < minimum_memory_mb
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment