diff --git a/router/files/99-router.conf b/router/roles/router/files/99-router.conf similarity index 100% rename from router/files/99-router.conf rename to router/roles/router/files/99-router.conf diff --git a/router/files/armbian.yaml b/router/roles/router/files/armbian.yaml similarity index 100% rename from router/files/armbian.yaml rename to router/roles/router/files/armbian.yaml diff --git a/router/files/lan.conf b/router/roles/router/files/lan.conf similarity index 100% rename from router/files/lan.conf rename to router/roles/router/files/lan.conf diff --git a/router/files/nftables.conf b/router/roles/router/files/nftables.conf similarity index 100% rename from router/files/nftables.conf rename to router/roles/router/files/nftables.conf diff --git a/router/roles/router/handlers/main.yml b/router/roles/router/handlers/main.yml new file mode 100644 index 0000000..c9dcd4c --- /dev/null +++ b/router/roles/router/handlers/main.yml @@ -0,0 +1,13 @@ +- name: Apply netplan configuration + ansible.builtin.command: + cmd: netplan apply + +- name: Restart dnsmasq + ansible.builtin.service: + name: dnsmasq.service + state: restarted + +- name: Restart nftables + ansible.builtin.service: + name: nftables.service + state: restarted diff --git a/router/roles/router/tasks/main.yml b/router/roles/router/tasks/main.yml new file mode 100644 index 0000000..181f313 --- /dev/null +++ b/router/roles/router/tasks/main.yml @@ -0,0 +1,63 @@ +# Configure netplan +- name: Copy armbian.yaml file + ansible.builtin.copy: + src: armbian.yaml + dest: /etc/netplan/armbian.yaml + mode: '0644' + owner: root + group: root + notify: + - Apply netplan configuration + +# Configure dnsmasq +- name: Ensure that dnsmasq is installed + ansible.builtin.apt: + name: dnsmasq + state: present + update_cache: yes +- name: Copy lan.conf file + ansible.builtin.copy: + src: lan.conf + dest: /etc/dnsmasq.d/lan.conf + mode: '0644' + owner: root + group: root + notify: + - Restart dnsmasq + +# Configure nftables +- name: Ensure that nftables is installed + ansible.builtin.apt: + name: nftables + state: present + update_cache: yes +- name: Copy nftables.conf file + ansible.builtin.copy: + src: nftables.conf + dest: /etc/nftables.conf + mode: '0644' + owner: root + group: root + notify: + - Restart nftables + +# Configure ip forwarding +- name: Copy 99-router.conf file + ansible.builtin.copy: + src: 99-router.conf + dest: /etc/sysctl.d/99-router.conf + mode: '0644' + owner: root + group: root + notify: + - Apply sysctl configuration + +# Ensure services are enabled +- name: Ensure dnsmasq service is enabled + ansible.builtin.service: + name: dnsmasq.service + enabled: true +- name: Ensure nftables service is enabled + ansible.builtin.service: + name: nftables.service + enabled: true diff --git a/router/roles/secure_conf/tasks/main.yml b/router/roles/secure_conf/tasks/main.yml new file mode 100644 index 0000000..44c9986 --- /dev/null +++ b/router/roles/secure_conf/tasks/main.yml @@ -0,0 +1,27 @@ +# Enable unattended-upgrades +- name: Install unattended-upgrades and apt-list changes + ansible.builtin.apt: + name: + - unattended-upgrades + - apt-listchanges + state: present + update_cache: yes + +- name: Enable auto updates + ansible.builtin.shell: echo unattended-upgrades unattended-upgrades/enable_auto_updates boolean true | debconf-set-selections + +- name: DPKG reconfigure + ansible.builtin.command: dpkg-reconfigure -f noninteractive unattended-upgrades + +# Secure configuration in /etc/ssh/ssh_config file +- name: sshd secure configuration + ansible.builtin.blockinfile: + name: /etc/ssh/sshd_config + block: | + Port 22 + PermitRootLogin no + PasswordAuthentication no + PubkeyAuthentication yes + X11Forwarding no + marker: "# {mark} sshd configuration" + insertafter: EOF diff --git a/router/files/wg0.conf b/router/roles/vpn/files/wg0.conf similarity index 100% rename from router/files/wg0.conf rename to router/roles/vpn/files/wg0.conf diff --git a/router/roles/vpn/handlers/main.yml b/router/roles/vpn/handlers/main.yml new file mode 100644 index 0000000..90c19b4 --- /dev/null +++ b/router/roles/vpn/handlers/main.yml @@ -0,0 +1,4 @@ +- name: Restart wireguard + ansible.builtin.service: + name: wg-quick@wg0.service + state: restarted diff --git a/router/roles/vpn/tasks/main.yml b/router/roles/vpn/tasks/main.yml new file mode 100644 index 0000000..f4dfd8e --- /dev/null +++ b/router/roles/vpn/tasks/main.yml @@ -0,0 +1,28 @@ +# Configure WireGuard +- name: Ensure that wireguard-tools is installed + ansible.builtin.apt: + name: wireguard-tools + state: present + update_cache: yes +- name: Create wireguard directory + ansible.builtin.file: + path: /etc/wireguard + state: directory + mode: '0700' + owner: root + group: root +- name: Copy wg0.conf file + ansible.builtin.copy: + src: wg0.conf + dest: /etc/wireguard/wg0.conf + mode: '0600' + owner: root + group: root + notify: + - Restart wireguard + +# Ensure wireguard is enabled +- name: Ensure wireguard service is enabled + ansible.builtin.service: + name: wg-quick@wg0.service + enabled: true diff --git a/router/router.yml b/router/router.yml index e09801d..06bd31a 100644 --- a/router/router.yml +++ b/router/router.yml @@ -2,122 +2,12 @@ hosts: routers become: true - tasks: - # Apply basic configuration - - ansible.builtin.import_tasks: tasks/unattended-upgrades.yml - - ansible.builtin.import_tasks: tasks/sshd.yml - - # Configure netplan - - name: Copy armbian.yaml file - ansible.builtin.copy: - src: files/armbian.yaml - dest: /etc/netplan/armbian.yaml - mode: '0644' - owner: root - group: root - notify: - - Apply netplan configuration - - # Configure dnsmasq - - name: Ensure that dnsmasq is installed - ansible.builtin.apt: - name: dnsmasq - state: present - update_cache: yes - - name: Copy lan.conf file - ansible.builtin.copy: - src: files/lan.conf - dest: /etc/dnsmasq.d/lan.conf - mode: '0644' - owner: root - group: root - notify: - - Restart dnsmasq - - # Configure nftables - - name: Ensure that nftables is installed - ansible.builtin.apt: - name: nftables - state: present - update_cache: yes - - name: Copy nftables.conf file - ansible.builtin.copy: - src: files/nftables.conf - dest: /etc/nftables.conf - mode: '0644' - owner: root - group: root - notify: - - Restart nftables - - # Configure ip forwarding - - name: Copy 99-router.conf file - ansible.builtin.copy: - src: files/99-router.conf - dest: /etc/sysctl.d/99-router.conf - mode: '0644' - owner: root - group: root - notify: - - Apply sysctl configuration - - # Configure WireGuard - - name: Ensure that wireguard-tools is installed - ansible.builtin.apt: - name: wireguard-tools - state: present - update_cache: yes - - name: Create wireguard directory - ansible.builtin.file: - path: /etc/wireguard - state: directory - mode: '0700' - owner: root - group: root - - name: Copy wg0.conf file - ansible.builtin.copy: - src: files/wg0.conf - dest: /etc/wireguard/wg0.conf - mode: '0600' - owner: root - group: root - notify: - - Restart wireguard - - # Ensure services are enabled - - name: Ensure dnsmasq service is enabled - ansible.builtin.service: - name: dnsmasq.service - enabled: true - - name: Ensure nftables service is enabled - ansible.builtin.service: - name: nftables.service - enabled: true - - name: Ensure wireguard service is enabled - ansible.builtin.service: - name: wg-quick@wg0.service - enabled: true + roles: + - secure_conf # Apply basic configuration + - vpn # VPN configuration + - router # Router configuration handlers: - - name: Apply netplan configuration - ansible.builtin.command: - cmd: netplan apply - - - name: Restart dnsmasq - ansible.builtin.service: - name: dnsmasq.service - state: restarted - - - name: Restart wireguard - ansible.builtin.service: - name: wg-quick@wg0.service - state: restarted - - - name: Restart nftables - ansible.builtin.service: - name: nftables.service - state: restarted - - name: Apply sysctl configuration ansible.builtin.command: cmd: sysctl --system diff --git a/router/tasks/sshd.yml b/router/tasks/sshd.yml deleted file mode 100644 index 5e68809..0000000 --- a/router/tasks/sshd.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- - - name: sshd secure configuration - ansible.builtin.blockinfile: - name: /etc/ssh/sshd_config - block: | - Port 22 - PermitRootLogin no - PasswordAuthentication no - PubkeyAuthentication yes - X11Forwarding no - marker: "# {mark} sshd configuration" - insertafter: EOF -... diff --git a/router/tasks/unattended-upgrades.yml b/router/tasks/unattended-upgrades.yml deleted file mode 100644 index 218a1b5..0000000 --- a/router/tasks/unattended-upgrades.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- - - name: Install unattended-upgrades and apt-list changes - ansible.builtin.apt: - name: - - unattended-upgrades - - apt-listchanges - state: present - update_cache: yes - - - name: Enable auto updates - ansible.builtin.shell: echo unattended-upgrades unattended-upgrades/enable_auto_updates boolean true | debconf-set-selections - - - name: DPKG reconfigure - ansible.builtin.command: dpkg-reconfigure -f noninteractive unattended-upgrades -...