diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..69ab028 --- /dev/null +++ b/.gitlab-ci.yml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c9c31f0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/ansible.cfg b/ansible.cfg index 26730d6..04991b7 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -14,4 +14,4 @@ interpreter_python = auto_silent roles_path = roles [ssh_connection] -pipelining = True \ No newline at end of file +pipelining = True diff --git a/inventories/prod/group_vars/all.yml b/inventories/prod/group_vars/all.yml index 8bd753c..4642c29 100644 --- a/inventories/prod/group_vars/all.yml +++ b/inventories/prod/group_vars/all.yml @@ -1,5 +1,4 @@ timezone: Europe/Berlin - common_packages: - vim - curl @@ -8,4 +7,4 @@ common_packages: - net-tools - tcpdump - htop - - unzip \ No newline at end of file + - unzip diff --git a/inventories/prod/hosts.ini b/inventories/prod/hosts.ini index 38f1e28..c05ca58 100644 --- a/inventories/prod/hosts.ini +++ b/inventories/prod/hosts.ini @@ -1,4 +1,4 @@ [vpn_nodes] # vpn01 ansible_host=65.108.87.246 private_ip=10.100.0.1 vpn01-test ansible_host=65.108.95.144 private_ip=10.100.0.2 -# vpn01-bmw ansible_host=65.108.93.171 private_ip=10.100.0.3 \ No newline at end of file +# vpn01-bmw ansible_host=65.108.93.171 private_ip=10.100.0.3 diff --git a/playbooks/bootstrap.yml b/playbooks/bootstrap.yml index 491e85b..ae3239c 100644 --- a/playbooks/bootstrap.yml +++ b/playbooks/bootstrap.yml @@ -4,4 +4,4 @@ become: true roles: - - common \ No newline at end of file + - common diff --git a/playbooks/monitoring.yml b/playbooks/monitoring.yml deleted file mode 100644 index e69de29..0000000 diff --git a/playbooks/networking.yml b/playbooks/networking.yml index 97caa68..0cbd0a0 100644 --- a/playbooks/networking.yml +++ b/playbooks/networking.yml @@ -4,4 +4,4 @@ become: true roles: - - networking \ No newline at end of file + - networking diff --git a/playbooks/openvpn.yml b/playbooks/openvpn.yml index 85e9754..f128499 100644 --- a/playbooks/openvpn.yml +++ b/playbooks/openvpn.yml @@ -6,5 +6,5 @@ roles: - common - networking - - radius-nat - - openvpn \ No newline at end of file + - radius_nat + - openvpn diff --git a/playbooks/radius-nat.yml b/playbooks/radius-nat.yml index 4e5deef..cbcb117 100644 --- a/playbooks/radius-nat.yml +++ b/playbooks/radius-nat.yml @@ -4,4 +4,4 @@ become: true roles: - - radius-nat \ No newline at end of file + - radius_nat diff --git a/roles/common/handlers/main.yml b/roles/common/handlers/main.yml deleted file mode 100644 index 73b314f..0000000 --- a/roles/common/handlers/main.yml +++ /dev/null @@ -1 +0,0 @@ ---- \ No newline at end of file diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 17fd83a..4bac2d4 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -1,18 +1,18 @@ --- - name: Update apt cache - apt: + ansible.builtin.apt: update_cache: true cache_valid_time: 3600 - name: Upgrade packages - apt: + ansible.builtin.apt: upgrade: dist - name: Install common packages - apt: + ansible.builtin.apt: name: "{{ common_packages }}" state: present - name: Configure timezone - timezone: - name: "{{ timezone }}" \ No newline at end of file + community.general.timezone: + name: "{{ timezone }}" diff --git a/roles/networking/defaults/main.yml b/roles/networking/defaults/main.yml deleted file mode 100644 index 4afc3c6..0000000 --- a/roles/networking/defaults/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# defaults file for roles/networking diff --git a/roles/networking/handlers/main.yml b/roles/networking/handlers/main.yml index 19e0c71..b4f496e 100644 --- a/roles/networking/handlers/main.yml +++ b/roles/networking/handlers/main.yml @@ -1,4 +1,5 @@ --- # handlers file for roles/networking -- name: reload sysctl - command: sysctl --system \ No newline at end of file +- name: Reload sysctl + ansible.builtin.command: sysctl --system + changed_when: false diff --git a/roles/networking/tasks/bridge.yml b/roles/networking/tasks/bridge.yml index da17cda..3b8460b 100644 --- a/roles/networking/tasks/bridge.yml +++ b/roles/networking/tasks/bridge.yml @@ -1,19 +1,19 @@ --- - name: Ensure bridge-utils is installed - apt: + ansible.builtin.apt: name: - bridge-utils - vlan - iproute2 - state: present + state: present - 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 failed_when: false changed_when: bridge_create.rc == 0 - 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 - changed_when: false \ No newline at end of file + changed_when: false diff --git a/roles/networking/tasks/main.yml b/roles/networking/tasks/main.yml index 18e0c67..e09b598 100644 --- a/roles/networking/tasks/main.yml +++ b/roles/networking/tasks/main.yml @@ -1,7 +1,7 @@ --- # tasks file for roles/networking - name: Deploy networking sysctl configuration - template: + ansible.builtin.template: src: 99-openvpn.conf.j2 dest: /etc/sysctl.d/99-openvpn.conf owner: root @@ -10,7 +10,8 @@ notify: reload sysctl - name: Apply sysctl immediately - command: sysctl --system + ansible.builtin.command: sysctl --system changed_when: false -- import_tasks: bridge.yml \ No newline at end of file +- name: Import bridge configuration tasks + ansible.builtin.import_tasks: bridge.yml diff --git a/roles/networking/templates/99-openvpn.conf.j2 b/roles/networking/templates/99-openvpn.conf.j2 index cfb3c87..2a0167b 100644 --- a/roles/networking/templates/99-openvpn.conf.j2 +++ b/roles/networking/templates/99-openvpn.conf.j2 @@ -3,4 +3,4 @@ net.ipv4.ip_forward=1 net.ipv4.conf.all.rp_filter=0 net.ipv4.conf.default.rp_filter=0 -net.ipv4.conf.enp7s0.rp_filter=0 \ No newline at end of file +net.ipv4.conf.enp7s0.rp_filter=0 diff --git a/roles/openvpn/defaults/main.yml b/roles/openvpn/defaults/main.yml index a829512..0d470eb 100644 --- a/roles/openvpn/defaults/main.yml +++ b/roles/openvpn/defaults/main.yml @@ -14,4 +14,4 @@ radius_acct_port: 1813 radius_shared_secret: aloulou nas_identifier: "{{ inventory_hostname }}" -nas_ip_address: "{{ private_ip }}" \ No newline at end of file +nas_ip_address: "{{ private_ip }}" diff --git a/roles/openvpn/files/certs/ca.crt b/roles/openvpn/files/certs/ca.crt index 0a7cca4..3f3586a 100644 --- a/roles/openvpn/files/certs/ca.crt +++ b/roles/openvpn/files/certs/ca.crt @@ -20,4 +20,4 @@ KoZIhvcNAQELBQADggEBAEAcp8h4rfB0OoGWmMBOmb6PP+0XpNHSfII86Tq3P0C0 Z8ILE5+Wi5sPK2QCCiYZngv+Piauo2cno9mKGkrNYQjI6Da0Ve8n+UIkGirbYQLb nwwSHLUIoXhLMh21Gmlw6cHPlzUws+G8eyfGUYolE8S+K8Dlpmhhse1dGZhW/iDV f8rOFkvWgtXIie5ljdSA2Ez9Tg1vQQIdgxKAW62I4Jk= ------END CERTIFICATE----- \ No newline at end of file +-----END CERTIFICATE----- diff --git a/roles/openvpn/files/certs/server.crt b/roles/openvpn/files/certs/server.crt index 01c145d..ecc47f0 100644 --- a/roles/openvpn/files/certs/server.crt +++ b/roles/openvpn/files/certs/server.crt @@ -22,4 +22,4 @@ FkH+KDL7EH77tMXQceJroM1/RFLotbwoT+QegENTHYf2pWTFikdMissSlWBzG7P/ Vv3qY//LGJBtejvJWdNKE179S/X0Emyj0HWcNJ63ZxTvxbs+xVf4X4qNKY1JyGS2 WtWquMJAfgD9hfr9fDptt+fAq4zTiTZ0Xrxs3uYo5xFszNvYevl4900ZvrQwygve ywb75tRo2g== ------END CERTIFICATE----- \ No newline at end of file +-----END CERTIFICATE----- diff --git a/roles/openvpn/files/certs/server.key b/roles/openvpn/files/certs/server.key index b740748..0374e7f 100644 --- a/roles/openvpn/files/certs/server.key +++ b/roles/openvpn/files/certs/server.key @@ -24,4 +24,4 @@ GR/j0jE0y+aV/Ai6j9iGNPiye7si6YMhBVYjZWaugQ9k8LeNO8NIgCHxvczIg8R9 J8M+gQKBgCa8WFdvu4mwjfX+rkOyVpkY/rmktgMot1YRarC9xSDaOydS5C1D++UU NxPRDwb7Ci1GNPAEHofOXXDLFVwlqJFg8meoYET4tP5L5dKb0MlQfb2dWyCITsNf WVBGoDNIW3jbOD5/hPS8TfFvAVsRggMQTPSiMr5Z+pLrIoj45VkO ------END RSA PRIVATE KEY----- \ No newline at end of file +-----END RSA PRIVATE KEY----- diff --git a/roles/openvpn/files/client-connect.sh b/roles/openvpn/files/client-connect.sh index c39946e..672ce15 100644 --- a/roles/openvpn/files/client-connect.sh +++ b/roles/openvpn/files/client-connect.sh @@ -7,4 +7,4 @@ if [ -n "$VLAN_ID" ]; then echo "vlan-pvid $VLAN_ID" >> "$client_connect_config_file" fi -exit 0 \ No newline at end of file +exit 0 diff --git a/roles/openvpn/handlers/main.yml b/roles/openvpn/handlers/main.yml index 801dfcc..ee4eaa5 100644 --- a/roles/openvpn/handlers/main.yml +++ b/roles/openvpn/handlers/main.yml @@ -1,5 +1,5 @@ --- -- name: restart openvpn - systemd: +- name: Restart openvpn + ansible.builtin.systemd: name: "{{ openvpn_service }}" - state: restarted \ No newline at end of file + state: restarted diff --git a/roles/openvpn/tasks/bridge-tap.yml b/roles/openvpn/tasks/bridge-tap.yml index 567ee49..d3edbf0 100644 --- a/roles/openvpn/tasks/bridge-tap.yml +++ b/roles/openvpn/tasks/bridge-tap.yml @@ -1,19 +1,22 @@ --- - name: Start OpenVPN - systemd: + ansible.builtin.systemd: name: "{{ openvpn_service }}" state: started enabled: true - name: Wait for tap0 - command: ip link show tap0 + ansible.builtin.command: ip link show tap0 register: tap_check retries: 10 delay: 2 until: tap_check.rc == 0 + changed_when: false - 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 - command: ip link set tap0 master br-main-vpn \ No newline at end of file + ansible.builtin.command: ip link set tap0 master br-main-vpn + changed_when: false diff --git a/roles/openvpn/tasks/certs.yml b/roles/openvpn/tasks/certs.yml index ae57f1a..f5b23c0 100644 --- a/roles/openvpn/tasks/certs.yml +++ b/roles/openvpn/tasks/certs.yml @@ -1,6 +1,6 @@ --- - name: Create certificate directory - file: + ansible.builtin.file: path: "{{ openvpn_cert_dir }}" state: directory owner: root @@ -8,7 +8,7 @@ mode: "0755" - name: Deploy CA certificate - copy: + ansible.builtin.copy: src: certs/ca.crt dest: "{{ openvpn_cert_dir }}/ca.crt" owner: root @@ -16,7 +16,7 @@ mode: "0644" - name: Deploy server certificate - copy: + ansible.builtin.copy: src: certs/server.crt dest: "{{ openvpn_cert_dir }}/server.crt" owner: root @@ -24,9 +24,9 @@ mode: "0644" - name: Deploy server private key - copy: + ansible.builtin.copy: src: certs/server.key dest: "{{ openvpn_cert_dir }}/server.key" owner: root group: root - mode: "0600" \ No newline at end of file + mode: "0600" diff --git a/roles/openvpn/tasks/config.yml b/roles/openvpn/tasks/config.yml index 354a50f..7397aa3 100644 --- a/roles/openvpn/tasks/config.yml +++ b/roles/openvpn/tasks/config.yml @@ -1,6 +1,6 @@ --- - name: Deploy OpenVPN configuration - template: + ansible.builtin.template: src: server.conf.j2 dest: /etc/openvpn/server/server.conf owner: root @@ -9,7 +9,7 @@ notify: restart openvpn - name: Deploy Radius configuration - template: + ansible.builtin.template: src: radiusplugin.cnf.j2 dest: /etc/openvpn/radiusplugin.cnf owner: root @@ -18,7 +18,7 @@ notify: restart openvpn - name: Deploy client-connect script - copy: + ansible.builtin.copy: src: client-connect.sh dest: /etc/openvpn/scripts/client-connect.sh owner: root @@ -26,6 +26,6 @@ mode: "0755" - name: Enable OpenVPN service - systemd: + ansible.builtin.systemd: name: openvpn@server - enabled: true \ No newline at end of file + enabled: true diff --git a/roles/openvpn/tasks/install.yml b/roles/openvpn/tasks/install.yml index 10ce7e2..bdd86f6 100644 --- a/roles/openvpn/tasks/install.yml +++ b/roles/openvpn/tasks/install.yml @@ -1,6 +1,6 @@ --- - name: Install OpenVPN packages - apt: + ansible.builtin.apt: name: - openvpn - openvpn-auth-radius @@ -8,7 +8,7 @@ update_cache: true - name: Create OpenVPN directories - file: + ansible.builtin.file: path: "{{ item }}" state: directory owner: root @@ -17,4 +17,4 @@ loop: - "{{ openvpn_ccd_dir }}" - "{{ openvpn_config_dir }}" - - /etc/openvpn/scripts \ No newline at end of file + - /etc/openvpn/scripts diff --git a/roles/openvpn/tasks/main.yml b/roles/openvpn/tasks/main.yml index 8396c97..72bfa45 100644 --- a/roles/openvpn/tasks/main.yml +++ b/roles/openvpn/tasks/main.yml @@ -1,5 +1,9 @@ --- -- import_tasks: install.yml -- import_tasks: certs.yml -- import_tasks: config.yml -- import_tasks: bridge-tap.yml \ No newline at end of file +- name: Import OpenVPN installation tasks + ansible.builtin.import_tasks: install.yml +- name: Import OpenVPN certificate tasks + 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 diff --git a/roles/openvpn/templates/radiusplugin.cnf.j2 b/roles/openvpn/templates/radiusplugin.cnf.j2 index 55aafb8..e372151 100644 --- a/roles/openvpn/templates/radiusplugin.cnf.j2 +++ b/roles/openvpn/templates/radiusplugin.cnf.j2 @@ -28,4 +28,4 @@ server retry=3 wait=10 -} \ No newline at end of file +} diff --git a/roles/openvpn/templates/server.conf.j2 b/roles/openvpn/templates/server.conf.j2 index bfc4e1d..5256976 100644 --- a/roles/openvpn/templates/server.conf.j2 +++ b/roles/openvpn/templates/server.conf.j2 @@ -42,4 +42,4 @@ tun-mtu 1400 verb 3 -status /var/log/openvpn-status.log \ No newline at end of file +status /var/log/openvpn-status.log diff --git a/roles/radius-nat/defaults/main.yml b/roles/radius_nat/defaults/main.yml similarity index 71% rename from roles/radius-nat/defaults/main.yml rename to roles/radius_nat/defaults/main.yml index a08fea3..fbfec40 100644 --- a/roles/radius-nat/defaults/main.yml +++ b/roles/radius_nat/defaults/main.yml @@ -1,4 +1,4 @@ --- # defaults file for roles/networking radius_auth_nodeport: 30131 -radius_acct_nodeport: 31622 \ No newline at end of file +radius_acct_nodeport: 31622 diff --git a/roles/radius-nat/tasks/main.yml b/roles/radius_nat/tasks/main.yml similarity index 76% rename from roles/radius-nat/tasks/main.yml rename to roles/radius_nat/tasks/main.yml index a8ce52b..2cdecf2 100644 --- a/roles/radius-nat/tasks/main.yml +++ b/roles/radius_nat/tasks/main.yml @@ -1,12 +1,12 @@ --- - name: Install iptables persistence - apt: + ansible.builtin.apt: name: - iptables-persistent state: present - name: DNAT RADIUS auth traffic - iptables: + ansible.builtin.iptables: table: nat chain: OUTPUT protocol: udp @@ -15,7 +15,7 @@ to_destination: ":{{ radius_auth_nodeport }}" - name: DNAT RADIUS accounting traffic - iptables: + ansible.builtin.iptables: table: nat chain: OUTPUT protocol: udp @@ -24,4 +24,5 @@ to_destination: ":{{ radius_acct_nodeport }}" - name: Save iptables rules - command: netfilter-persistent save \ No newline at end of file + ansible.builtin.command: netfilter-persistent save + changed_when: false