diff --git a/.gitea/workflows/ansible-runner.yaml b/.gitea/workflows/ansible-runner.yaml index 7520214..69c0160 100644 --- a/.gitea/workflows/ansible-runner.yaml +++ b/.gitea/workflows/ansible-runner.yaml @@ -64,10 +64,12 @@ jobs: - name: 🔎Check Ansible Playbook Syntax 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 - name: 🏃‍♂️Run Ansible Playbook 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 \ No newline at end of file diff --git a/playbooks/deploy_swapfile.yml.ansible b/playbooks/deploy_swapfile.yml.ansible new file mode 100644 index 0000000..5f4d1ad --- /dev/null +++ b/playbooks/deploy_swapfile.yml.ansible @@ -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 \ No newline at end of file