add swapfile support
Some checks failed
🏃‍♂️Run Ansible / install_ansible (push) Failing after 8m22s

This commit is contained in:
Ronny
2025-12-11 15:10:30 +00:00
parent a37e97481b
commit e7aac9feb6
2 changed files with 63 additions and 2 deletions

View File

@@ -64,10 +64,12 @@ jobs:
- name: 🔎Check Ansible Playbook Syntax - name: 🔎Check Ansible Playbook Syntax
run: | run: |
ansible-playbook --syntax-check playbooks/update_debian.yml.ansible ansible-playbook --syntax-check playbooks/deploy_swapfile.yml.ansible
# ansible-playbook --syntax-check playbooks/update_debian.yml.ansible
ansible-playbook --syntax-check playbooks/install_postgresql.yml.ansible ansible-playbook --syntax-check playbooks/install_postgresql.yml.ansible
- name: 🏃Run Ansible Playbook - name: 🏃Run Ansible Playbook
run: | run: |
ansible-playbook -i inventory/raspberries.yaml playbooks/update_debian.yml.ansible --vault-password-file .vault_pass.txt ansible-playbook -i inventory/raspberries.yaml playbooks/deploy_swapfile.yml.ansible --vault-password-file .vault_pass.txt
# ansible-playbook -i inventory/raspberries.yaml playbooks/update_debian.yml.ansible --vault-password-file .vault_pass.txt
ansible-playbook -i inventory/raspberries.yaml playbooks/install_postgresql.yml.ansible --vault-password-file .vault_pass.txt ansible-playbook -i inventory/raspberries.yaml playbooks/install_postgresql.yml.ansible --vault-password-file .vault_pass.txt

View File

@@ -0,0 +1,59 @@
- name: Configure swap file for PostgreSQL node
hosts: dev
become: true
vars:
swap_file_path: /swapfile
swap_file_size_mb: 4096 # 4 GB
tasks:
- name: Check if swap file already exists
stat:
path: "{{ swap_file_path }}"
register: swap_file_check
- name: Create swap file
command: dd if=/dev/zero of={{ swap_file_path }} bs=1M count={{ swap_file_size_mb }}
when: not swap_file_check.stat.exists
register: swap_created
- name: Set correct permissions on swap file
file:
path: "{{ swap_file_path }}"
owner: root
group: root
mode: '0600'
when: swap_created is changed
- name: Format swap file
command: mkswap {{ swap_file_path }}
when: swap_created is changed
register: swap_formatted
- name: Enable swap file
command: swapon {{ swap_file_path }}
when: swap_formatted is changed
- name: Check if swap is already in fstab
lineinfile:
path: /etc/fstab
regexp: '^{{ swap_file_path }}'
state: absent
check_mode: true
register: fstab_check
changed_when: false
- name: Add swap to fstab for persistence
lineinfile:
path: /etc/fstab
line: '{{ swap_file_path }} none swap sw 0 0'
state: present
when: fstab_check.found == 0
- name: Verify swap is active
command: swapon --show
register: swap_status
changed_when: false
- name: Display swap status
debug:
var: swap_status.stdout_lines