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
1 changed files with 41 additions and 1 deletions

View File

@ -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:
@ -12,4 +15,41 @@
ansible.builtin.apt:
pkg:
- 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"