Skip to content

Commit

Permalink
Merge pull request #28 from valiantlynx/working
Browse files Browse the repository at this point in the history
Update main.yml
  • Loading branch information
valiantlynx authored Apr 1, 2024
2 parents d48acc1 + 202c40d commit c719e3e
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions ansible/roles/ec2-swap/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
---
- name: Remove useless packages from the cache
become: true
become_user: root
become_method: sudo
tasks:
- name: Remove useless packages from the cache
apt:
autoclean: yes
- name: Set up the swap area
command: mkswap /dev/nvme1n1
- name: Enable swap
command: swapon /dev/nvme1n1
- name: Make this swap setting persist by adding following line in /etc/fstab
command: echo "/dev/nvme1n1 none swap sw 0 0" >> /etc/fstab
apt:
autoclean: yes

- name: Check if swap file already exists
become: true
ansible.builtin.stat:
path: /swapfile
register: swapfile

- name: Create a 1GB swap file
become: true
command: fallocate -l 1G /swapfile
when: not swapfile.stat.exists

- name: Secure swap file by setting up correct permissions
become: true
command: chmod 600 /swapfile
when: not swapfile.stat.exists

- name: Set up the swap area
become: true
command: mkswap /swapfile
when: not swapfile.stat.exists

- name: Enable swap
become: true
command: swapon /swapfile
when: not swapfile.stat.exists

- name: Make this swap setting persist by adding following line in /etc/fstab
become: true
lineinfile:
path: /etc/fstab
line: '/swapfile swap swap defaults 0 0'
create: yes
state: present
when: not swapfile.stat.exists

0 comments on commit c719e3e

Please sign in to comment.