Commit 9c2435d1 by Braden MacDonald

Merge pull request #2451 from open-craft/optional-swap-role

Add a swapfile role to edx_sandbox playbook
parents 58c774aa d177774c
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
when: ENABLE_LEGACY_ORA when: ENABLE_LEGACY_ORA
- certs - certs
- edx_ansible - edx_ansible
- { role: swapfile, SWAPFILE_SIZE: "2GB" }
- role: datadog - role: datadog
when: COMMON_ENABLE_DATADOG when: COMMON_ENABLE_DATADOG
- role: splunkforwarder - role: splunkforwarder
......
The MIT License (MIT)
Copyright (c) 2014 Kamal Nasser <hello@kamal.io>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
swapfile
========
Creates and enables a swap file.
Slightly modified from https://github.com/kamaln7/ansible-swapfile
## License
The MIT License (MIT)
Copyright (c) 2014 Kamal Nasser <hello@kamal.io>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
---
# Size of the desired swap file. Use a MB or GB suffix.
SWAPFILE_SIZE: 2GB
# SWAPFILE_LOCATION: Location of the swap file managed by this role.
SWAPFILE_LOCATION: /swapfile
# SWAPFILE_USE_DD: set this to True if your filesystem does not support
# fallocate (e.g. if you use ext3). dd will then be used instead of fallocate.
SWAPFILE_USE_DD: False
#
# Advanced, optional settings:
#
# SWAPFILE_SWAPPINESS: Update sysctl.conf to set the swappiness percentage
# (vm.swappiness) -- the lower it is, the less your system swaps memory pages.
# If this is False (default), no change will be made.
SWAPFILE_SWAPPINESS: False
# SWAPFILE_VFS_CACHE_PRESSURE: Update sysctl.conf to set the VFS cache pressure.
# "this percentage value controls the tendency of the kernel to reclaim the
# memory which is used for caching of directory and inode objects."
# If this is False (default), no change will be made.
SWAPFILE_VFS_CACHE_PRESSURE: False
---
- name: reload sysctl
command: sysctl -p
---
galaxy_info:
author: "Kamal Nasser"
description: swapfile
license: MIT
min_ansible_version: 1.4
version: 0.4
categories:
- system
dependencies: []
---
- name: Write swapfile
command: |
{% if SWAPFILE_USE_DD %}
dd if=/dev/zero of={{ SWAPFILE_LOCATION }} bs=1M count={{ SWAPFILE_SIZE }} creates={{ SWAPFILE_LOCATION }}
{% else %}
fallocate -l {{ SWAPFILE_SIZE }} {{ SWAPFILE_LOCATION }} creates={{ SWAPFILE_LOCATION }}
{% endif %}
register: write_swapfile
when: SWAPFILE_SIZE != false
- name: Set swapfile permissions
file: path={{ SWAPFILE_LOCATION }} mode=600
when: SWAPFILE_SIZE != false
- name: Create swapfile
command: mkswap {{ SWAPFILE_LOCATION }}
register: create_swapfile
when: SWAPFILE_SIZE != false and write_swapfile.changed
- name: Enable swapfile
command: swapon {{ SWAPFILE_LOCATION }}
when: SWAPFILE_SIZE != false and create_swapfile.changed
- name: Add swapfile to /etc/fstab
mount: name=none src="{{ SWAPFILE_LOCATION }}" fstype=swap opts=sw passno=0 dump=0 state=present
when: SWAPFILE_SIZE != false
- name: Configure vm.swappiness
lineinfile: dest=/etc/sysctl.conf line="vm.swappiness = {{ SWAPFILE_SWAPPINESS }}" regexp="^vm.swappiness[\s]?=" state=present
notify: reload sysctl
when: SWAPFILE_SWAPPINESS != false
- name: Configure vm.vfs_cache_pressure
lineinfile: dest=/etc/sysctl.conf line="vm.vfs_cache_pressure = {{ SWAPFILE_VFS_CACHE_PRESSURE }}" regexp="^vm.vfs_cache_pressure[\s]?=" state=present
notify: reload sysctl
when: SWAPFILE_VFS_CACHE_PRESSURE != false
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment