devstack-plugin-tobiko/roles/devstack-tobiko-deploy/tasks/add-swap-file.yaml
Federico Ressi 9108be7e83 Avoid re-stacking when not necessary
Also adds a swap file of 8GB

Change-Id: I50b7dcb5ca40c9840ae086006c9d868637d3b5d0
2020-10-02 15:39:53 +02:00

28 lines
662 B
YAML

---
- name: "Add a swap file of {{ swap_file_size }} MBytes"
become: true
become_user: root
shell:
cmd: |
# does the swap file already exist?
if grep -q "swapfile" /etc/fstab; then
echo 'swapfile found. No changes made.'
exit 0
fi
echo 'swapfile not found. Adding swapfile...'
set -ex
fallocate -l '{{ swap_file_size }}M' /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap defaults 0 0' >> /etc/fstab
echo 'swapfile added.'
exit 0
register: add_swap_file
changed_when: >-
'swapfile added' in add_swap_file.stdout