Simplify and consolidate scripts

This commit is contained in:
ducoterra
2022-02-05 22:30:44 -05:00
parent 1370897735
commit 8b3002316f
236 changed files with 444 additions and 1970 deletions

54
arch/swap/tasks/main.yml Normal file
View File

@@ -0,0 +1,54 @@
---
# Create swap
- name: Turn off swap
command: "swapoff --all"
become: yes
- name: Remove old swap file
file:
state: absent
path: "{{ swap_file_path }}"
become: yes
- name: Create swap file
command: truncate -s 0 "{{ swap_file_path }}"
creates="{{ swap_file_path }}"
become: yes
- name: Set swap compression
command: chattr +C "{{ swap_file_path }}"
become: yes
- name: Allocate swap space
command: fallocate -l "{{ swap_file_size_mb }}M" "{{ swap_file_path }}"
become: yes
- name: Change swap file permissions
file: path="{{ swap_file_path }}"
owner=root
group=root
mode=0600
become: yes
- name: "Check swap file type"
command: file {{ swap_file_path }}
register: swapfile
become: yes
- name: Make swap file
command: "mkswap {{ swap_file_path }}"
become: yes
- name: Write swap entry in fstab
mount: name=none
src={{ swap_file_path }}
fstype=swap
opts=sw
passno=0
dump=0
state=present
become: yes
- name: Mount swap
command: "swapon {{ swap_file_path }}"
become: yes
- name: Set swappiness
command: sysctl -w vm.swappiness=1
become: yes
- name: Make swappiness permanent
copy:
dest: "/etc/sysctl.d/99-swappiness.conf"
content: |
vm.swappiness=1
become: yes