role prepare node

This commit is contained in:
Fabio Sinibaldi 2026-07-30 18:05:46 +02:00
parent 7d3db6acd9
commit 2349b59eca
5 changed files with 41 additions and 31 deletions

View File

@ -0,0 +1,3 @@
---
configure_swap: true
ip_tables_config: true

View File

@ -1,34 +1,4 @@
---
- name: Update all packages
ansible.builtin.apt:
update_cache: true
upgrade: dist
- name: Install essential packages
ansible.builtin.apt:
name:
- net-tools
- curl
- wget
- htop
- vim
state: present
- name: Add 1GB swap file
ansible.builtin.shell: |
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
args:
creates: /swapfile
- name: Make swap persistent
ansible.builtin.lineinfile:
dest: /etc/fstab
line: '/swapfile none swap sw 0 0'
state: present
- name: Configure iptables firewall rules
ansible.builtin.iptables:
chain: INPUT
@ -42,9 +12,10 @@
- { protocol: tcp, port: '443', description: 'HTTPS for secure web traffic' }
- { protocol: udp, port: '51820', description: 'WireGuard VPN traffic' }
become: true
become_exe: "{{ become_exe_value }}"
register: iptables_result
- name: Display iptables configuration status
ansible.builtin.debug:
msg: "Configured firewall rules for ports: 80 (HTTP), 443 (HTTPS), 51820 (WireGuard UDP)"
when: iptables_result is changed
when: iptables_result is changed

View File

@ -0,0 +1,6 @@
---
- include_role: updates.yaml
- include_role: swap.yaml
when: configure_swap is defined
- include_role: iptables.yaml
when: ip_tables_coonfig is defined

View File

@ -0,0 +1,15 @@
---
- name: Add 1GB swap file
ansible.builtin.shell: |
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
args:
creates: /swapfile
- name: Make swap persistent
ansible.builtin.lineinfile:
dest: /etc/fstab
line: '/swapfile none swap sw 0 0'
state: present

View File

@ -0,0 +1,15 @@
---
- name: Update all packages
ansible.builtin.apt:
update_cache: true
upgrade: dist
- name: Install essential packages
ansible.builtin.apt:
name:
- net-tools
- curl
- wget
- htop
- vim
state: present