swap
This commit is contained in:
parent
682814a14f
commit
350e59322c
1 changed files with 41 additions and 1 deletions
|
@ -2,6 +2,9 @@
|
|||
- name: Update web servers
|
||||
hosts: all
|
||||
remote_user: root
|
||||
vars:
|
||||
swapfile_size: 1
|
||||
swapfile_path: /swapfile
|
||||
tasks:
|
||||
- name: Update all packages to their latest version
|
||||
ansible.builtin.apt:
|
||||
|
@ -13,3 +16,40 @@
|
|||
pkg:
|
||||
- htop
|
||||
- unp
|
||||
|
||||
- name: Create swap file
|
||||
command: |
|
||||
{% if swapfile_fallocate %}
|
||||
fallocate -l {{ ((swapfile_size) | int * 1024 * 1024) }} {{ swapfile_path }}
|
||||
{% else %}
|
||||
dd if=/dev/zero of={{ swapfile_path }} bs=1M count={{ swapfile_size }}
|
||||
{% endif %}
|
||||
args:
|
||||
creates: "{{ swapfile_path }}"
|
||||
register: swapfile_register_create
|
||||
|
||||
- name: Set swap file permissions
|
||||
file:
|
||||
path: "{{ swapfile_path }}"
|
||||
state: "file"
|
||||
owner: "root"
|
||||
group: "root"
|
||||
mode: "0600"
|
||||
|
||||
- name: Initialize swap file
|
||||
command: mkswap {{ swapfile_path }}
|
||||
when: swapfile_register_create is changed
|
||||
|
||||
- name: Enable swap file
|
||||
command: swapon {{ swapfile_path }}
|
||||
when: swapfile_register_create is changed
|
||||
|
||||
- name: Manage swap file in /etc/fstab
|
||||
mount:
|
||||
src: "{{ swapfile_path }}"
|
||||
name: "none"
|
||||
fstype: "swap"
|
||||
opts: "sw,nofail"
|
||||
dump: "0"
|
||||
passno: "0"
|
||||
state: "present"
|
Loading…
Reference in a new issue