chore: fix ansible-lint violations and add pre-commit hooks
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
default:
|
||||||
|
image: alpine/ansible:2.21.0
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
stages:
|
||||||
|
- validate
|
||||||
|
- deploy
|
||||||
|
|
||||||
|
ansible-lint:
|
||||||
|
stage: validate
|
||||||
|
script:
|
||||||
|
- ansible-lint
|
||||||
|
|
||||||
|
syntax-check:
|
||||||
|
stage: validate
|
||||||
|
script:
|
||||||
|
- ansible-playbook --syntax-check playbooks/openvpn.yml
|
||||||
|
|
||||||
|
deploy-prod:
|
||||||
|
stage: deploy
|
||||||
|
when: manual
|
||||||
|
script:
|
||||||
|
- ansible-playbook playbooks/openvpn.yml
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
repos:
|
||||||
|
# Optional: Add YAML validation hook
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v4.5.0
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace # Remove trailing spaces
|
||||||
|
- id: end-of-file-fixer # Ensure newline at end of files
|
||||||
|
- id: check-yaml # Basic YAML syntax check
|
||||||
|
- id: check-added-large-files # Prevent large files
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
timezone: Europe/Berlin
|
timezone: Europe/Berlin
|
||||||
|
|
||||||
common_packages:
|
common_packages:
|
||||||
- vim
|
- vim
|
||||||
- curl
|
- curl
|
||||||
|
|||||||
@@ -6,5 +6,5 @@
|
|||||||
roles:
|
roles:
|
||||||
- common
|
- common
|
||||||
- networking
|
- networking
|
||||||
- radius-nat
|
- radius_nat
|
||||||
- openvpn
|
- openvpn
|
||||||
@@ -4,4 +4,4 @@
|
|||||||
become: true
|
become: true
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
- radius-nat
|
- radius_nat
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
---
|
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
---
|
---
|
||||||
- name: Update apt cache
|
- name: Update apt cache
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
update_cache: true
|
update_cache: true
|
||||||
cache_valid_time: 3600
|
cache_valid_time: 3600
|
||||||
|
|
||||||
- name: Upgrade packages
|
- name: Upgrade packages
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
upgrade: dist
|
upgrade: dist
|
||||||
|
|
||||||
- name: Install common packages
|
- name: Install common packages
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
name: "{{ common_packages }}"
|
name: "{{ common_packages }}"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Configure timezone
|
- name: Configure timezone
|
||||||
timezone:
|
community.general.timezone:
|
||||||
name: "{{ timezone }}"
|
name: "{{ timezone }}"
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
---
|
|
||||||
# defaults file for roles/networking
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
---
|
---
|
||||||
# handlers file for roles/networking
|
# handlers file for roles/networking
|
||||||
- name: reload sysctl
|
- name: Reload sysctl
|
||||||
command: sysctl --system
|
ansible.builtin.command: sysctl --system
|
||||||
|
changed_when: false
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: Ensure bridge-utils is installed
|
- name: Ensure bridge-utils is installed
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- bridge-utils
|
- bridge-utils
|
||||||
- vlan
|
- vlan
|
||||||
@@ -8,12 +8,12 @@
|
|||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Create bridge if missing
|
- name: Create bridge if missing
|
||||||
command: ip link add br-main-vpn type bridge
|
ansible.builtin.command: ip link add br-main-vpn type bridge
|
||||||
register: bridge_create
|
register: bridge_create
|
||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: bridge_create.rc == 0
|
changed_when: bridge_create.rc == 0
|
||||||
|
|
||||||
- name: Bring bridge up
|
- name: Bring bridge up
|
||||||
command: ip link set br-main-vpn up
|
ansible.builtin.command: ip link set br-main-vpn up
|
||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: false
|
changed_when: false
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
# tasks file for roles/networking
|
# tasks file for roles/networking
|
||||||
- name: Deploy networking sysctl configuration
|
- name: Deploy networking sysctl configuration
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: 99-openvpn.conf.j2
|
src: 99-openvpn.conf.j2
|
||||||
dest: /etc/sysctl.d/99-openvpn.conf
|
dest: /etc/sysctl.d/99-openvpn.conf
|
||||||
owner: root
|
owner: root
|
||||||
@@ -10,7 +10,8 @@
|
|||||||
notify: reload sysctl
|
notify: reload sysctl
|
||||||
|
|
||||||
- name: Apply sysctl immediately
|
- name: Apply sysctl immediately
|
||||||
command: sysctl --system
|
ansible.builtin.command: sysctl --system
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- import_tasks: bridge.yml
|
- name: Import bridge configuration tasks
|
||||||
|
ansible.builtin.import_tasks: bridge.yml
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
- name: restart openvpn
|
- name: Restart openvpn
|
||||||
systemd:
|
ansible.builtin.systemd:
|
||||||
name: "{{ openvpn_service }}"
|
name: "{{ openvpn_service }}"
|
||||||
state: restarted
|
state: restarted
|
||||||
@@ -1,19 +1,22 @@
|
|||||||
---
|
---
|
||||||
- name: Start OpenVPN
|
- name: Start OpenVPN
|
||||||
systemd:
|
ansible.builtin.systemd:
|
||||||
name: "{{ openvpn_service }}"
|
name: "{{ openvpn_service }}"
|
||||||
state: started
|
state: started
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
- name: Wait for tap0
|
- name: Wait for tap0
|
||||||
command: ip link show tap0
|
ansible.builtin.command: ip link show tap0
|
||||||
register: tap_check
|
register: tap_check
|
||||||
retries: 10
|
retries: 10
|
||||||
delay: 2
|
delay: 2
|
||||||
until: tap_check.rc == 0
|
until: tap_check.rc == 0
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: Bring tap0 up
|
- name: Bring tap0 up
|
||||||
command: ip link set tap0 up
|
ansible.builtin.command: ip link set tap0 up
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: Attach tap0 to bridge
|
- name: Attach tap0 to bridge
|
||||||
command: ip link set tap0 master br-main-vpn
|
ansible.builtin.command: ip link set tap0 master br-main-vpn
|
||||||
|
changed_when: false
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: Create certificate directory
|
- name: Create certificate directory
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ openvpn_cert_dir }}"
|
path: "{{ openvpn_cert_dir }}"
|
||||||
state: directory
|
state: directory
|
||||||
owner: root
|
owner: root
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
mode: "0755"
|
mode: "0755"
|
||||||
|
|
||||||
- name: Deploy CA certificate
|
- name: Deploy CA certificate
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
src: certs/ca.crt
|
src: certs/ca.crt
|
||||||
dest: "{{ openvpn_cert_dir }}/ca.crt"
|
dest: "{{ openvpn_cert_dir }}/ca.crt"
|
||||||
owner: root
|
owner: root
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
|
||||||
- name: Deploy server certificate
|
- name: Deploy server certificate
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
src: certs/server.crt
|
src: certs/server.crt
|
||||||
dest: "{{ openvpn_cert_dir }}/server.crt"
|
dest: "{{ openvpn_cert_dir }}/server.crt"
|
||||||
owner: root
|
owner: root
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
|
||||||
- name: Deploy server private key
|
- name: Deploy server private key
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
src: certs/server.key
|
src: certs/server.key
|
||||||
dest: "{{ openvpn_cert_dir }}/server.key"
|
dest: "{{ openvpn_cert_dir }}/server.key"
|
||||||
owner: root
|
owner: root
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: Deploy OpenVPN configuration
|
- name: Deploy OpenVPN configuration
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: server.conf.j2
|
src: server.conf.j2
|
||||||
dest: /etc/openvpn/server/server.conf
|
dest: /etc/openvpn/server/server.conf
|
||||||
owner: root
|
owner: root
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
notify: restart openvpn
|
notify: restart openvpn
|
||||||
|
|
||||||
- name: Deploy Radius configuration
|
- name: Deploy Radius configuration
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: radiusplugin.cnf.j2
|
src: radiusplugin.cnf.j2
|
||||||
dest: /etc/openvpn/radiusplugin.cnf
|
dest: /etc/openvpn/radiusplugin.cnf
|
||||||
owner: root
|
owner: root
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
notify: restart openvpn
|
notify: restart openvpn
|
||||||
|
|
||||||
- name: Deploy client-connect script
|
- name: Deploy client-connect script
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
src: client-connect.sh
|
src: client-connect.sh
|
||||||
dest: /etc/openvpn/scripts/client-connect.sh
|
dest: /etc/openvpn/scripts/client-connect.sh
|
||||||
owner: root
|
owner: root
|
||||||
@@ -26,6 +26,6 @@
|
|||||||
mode: "0755"
|
mode: "0755"
|
||||||
|
|
||||||
- name: Enable OpenVPN service
|
- name: Enable OpenVPN service
|
||||||
systemd:
|
ansible.builtin.systemd:
|
||||||
name: openvpn@server
|
name: openvpn@server
|
||||||
enabled: true
|
enabled: true
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: Install OpenVPN packages
|
- name: Install OpenVPN packages
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- openvpn
|
- openvpn
|
||||||
- openvpn-auth-radius
|
- openvpn-auth-radius
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
update_cache: true
|
update_cache: true
|
||||||
|
|
||||||
- name: Create OpenVPN directories
|
- name: Create OpenVPN directories
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ item }}"
|
path: "{{ item }}"
|
||||||
state: directory
|
state: directory
|
||||||
owner: root
|
owner: root
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
---
|
---
|
||||||
- import_tasks: install.yml
|
- name: Import OpenVPN installation tasks
|
||||||
- import_tasks: certs.yml
|
ansible.builtin.import_tasks: install.yml
|
||||||
- import_tasks: config.yml
|
- name: Import OpenVPN certificate tasks
|
||||||
- import_tasks: bridge-tap.yml
|
ansible.builtin.import_tasks: certs.yml
|
||||||
|
- name: Import OpenVPN configuration tasks
|
||||||
|
ansible.builtin.import_tasks: config.yml
|
||||||
|
- name: Import OpenVPN bridge-tap tasks
|
||||||
|
ansible.builtin.import_tasks: bridge-tap.yml
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
---
|
---
|
||||||
- name: Install iptables persistence
|
- name: Install iptables persistence
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- iptables-persistent
|
- iptables-persistent
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: DNAT RADIUS auth traffic
|
- name: DNAT RADIUS auth traffic
|
||||||
iptables:
|
ansible.builtin.iptables:
|
||||||
table: nat
|
table: nat
|
||||||
chain: OUTPUT
|
chain: OUTPUT
|
||||||
protocol: udp
|
protocol: udp
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
to_destination: ":{{ radius_auth_nodeport }}"
|
to_destination: ":{{ radius_auth_nodeport }}"
|
||||||
|
|
||||||
- name: DNAT RADIUS accounting traffic
|
- name: DNAT RADIUS accounting traffic
|
||||||
iptables:
|
ansible.builtin.iptables:
|
||||||
table: nat
|
table: nat
|
||||||
chain: OUTPUT
|
chain: OUTPUT
|
||||||
protocol: udp
|
protocol: udp
|
||||||
@@ -24,4 +24,5 @@
|
|||||||
to_destination: ":{{ radius_acct_nodeport }}"
|
to_destination: ":{{ radius_acct_nodeport }}"
|
||||||
|
|
||||||
- name: Save iptables rules
|
- name: Save iptables rules
|
||||||
command: netfilter-persistent save
|
ansible.builtin.command: netfilter-persistent save
|
||||||
|
changed_when: false
|
||||||
Reference in New Issue
Block a user