This commit is contained in:
Kekskurse 2023-07-21 06:09:23 +02:00
parent 682814a14f
commit 350e59322c
Signed by: kekskurse
GPG key ID: 728ACCB59341E7E4

View file

@ -2,6 +2,9 @@
- name: Update web servers - name: Update web servers
hosts: all hosts: all
remote_user: root remote_user: root
vars:
swapfile_size: 1
swapfile_path: /swapfile
tasks: tasks:
- name: Update all packages to their latest version - name: Update all packages to their latest version
ansible.builtin.apt: ansible.builtin.apt:
@ -13,3 +16,40 @@
pkg: pkg:
- htop - htop
- unp - 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"