Commit 9efbb540 by Braden MacDonald

Add optional swap role that configures a swapfile

parent a0af0382
......@@ -51,6 +51,7 @@
when: ENABLE_LEGACY_ORA
- certs
- edx_ansible
- { role: swapfile, SWAPFILE_SIZE: "2GB" }
- role: datadog
when: COMMON_ENABLE_DATADOG
- 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.
---
# To enable the swapfile role, set this variable using a MB or GB suffix
# e.g. SWAPFILE_SIZE: 512MB
# To disable the role, leave the default value of 'false'
SWAPFILE_SIZE: false
swapfile_location: /swapfile
swapfile_swappiness: False
swapfile_vfs_cache_pressure: False
swapfile_use_dd: 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
lineinfile: dest=/etc/fstab line="{{ swapfile_location }} none swap sw 0 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