Compare commits

...

49 Commits

Author SHA1 Message Date
Fabio Sinibaldi 5413bb5036 Merge pull request 'wg_auto_clients' (#12) from wg_auto_clients into main
Reviewed-on: #12
2026-07-13 16:43:19 +02:00
Fabio Sinibaldi 2a7017a8c8 Update doc : vpn server playbook 2026-07-13 16:42:28 +02:00
Fabio Sinibaldi d0efa5e9be delete previous client configurations from local folder 2026-07-13 16:42:08 +02:00
Fabio Sinibaldi a6d9794abb Only generate configured peers and discard the rest 2026-07-13 15:20:31 +02:00
Fabio Sinibaldi 8a0ec15e56 Force key (re)generation if asked 2026-07-13 14:52:27 +02:00
Fabio Sinibaldi e9b251a18f cleanup 2026-07-13 14:29:40 +02:00
Fabio Sinibaldi 894cb17f7e Do not regenerate client keys if already configured on server 2026-07-13 14:28:57 +02:00
Fabio Sinibaldi 9aa2fe8bca Sifi vpn users 2026-07-10 17:20:45 +02:00
Fabio Sinibaldi 9e275303c9 Merge pull request 'wg_auto_clients' (#11) from wg_auto_clients into main
Reviewed-on: #11
2026-07-10 17:11:34 +02:00
Fabio Sinibaldi b0d53248ec GI ignore wg client configurations 2026-07-10 17:10:14 +02:00
Fabio Sinibaldi eb84432a4a WG Provisioning generates client keys if needed 2026-07-10 15:26:47 +02:00
Fabio Sinibaldi 1d970e843e Merge branch 'sifi' 2026-06-22 17:13:29 +02:00
Fabio Sinibaldi d60fafdf7e removed obsolete requirements file 2026-06-22 17:03:52 +02:00
Fabio Sinibaldi 3550797a5f requirements for wireguard role 2026-06-22 16:49:07 +02:00
Fabio Sinibaldi 2b18b0f316 Added vpn-1 server e dev-1 2026-06-22 16:49:07 +02:00
Fabio Sinibaldi 53a6db2fad Added vpn-1 server e dev-1 2026-06-22 16:49:07 +02:00
Fabio Sinibaldi a09e56f4e3 added lucio 2026-06-22 16:49:07 +02:00
Fabio Sinibaldi 0d7b47021e Make Apache listen to 443 2026-06-22 16:49:07 +02:00
Fabio Sinibaldi c3adcc1cf1 wireguard key fabio 2026-06-22 16:49:07 +02:00
Fabio Sinibaldi 4835be1e30 inventory update 2026-06-22 16:49:07 +02:00
Fabio Sinibaldi bba9096ac4 Fixed N Aio image tag and name 2026-06-22 16:49:07 +02:00
Fabio Sinibaldi a50ab533bc Nextcloud AIO 2026-06-22 16:49:07 +02:00
Fabio Sinibaldi cf83f7bd2c Misc tests 2026-06-22 16:47:46 +02:00
Fabio Sinibaldi e29626c550 Defined role wordpress-docker 2026-06-22 16:47:46 +02:00
Fabio Sinibaldi af433bf4f9 Set upload max file size to 20M 2026-06-22 16:47:46 +02:00
Fabio Sinibaldi 1ba1f48a67 Extended geerlingguy.certbot role 2026-06-22 16:47:46 +02:00
Fabio Sinibaldi 152f556d55 removed IP 2026-06-22 16:47:46 +02:00
Fabio Sinibaldi e864964b95 Https enabled and letsencrypt working 2026-06-22 16:47:46 +02:00
Fabio Sinibaldi 976b96b3bb Removed wrong imports 2026-06-22 16:47:46 +02:00
Fabio Sinibaldi ce83465f7b Https with letsencrypt 2026-06-22 16:47:46 +02:00
Fabio Sinibaldi 5472f1ff2a HTTP setup 2026-06-22 16:47:46 +02:00
Fabio Sinibaldi 7c837e3a74 Fixed templates folder 2026-06-22 16:45:33 +02:00
Fabio Sinibaldi 2d8495fb53 First try 2026-06-22 16:45:33 +02:00
Fabio Sinibaldi bb6c96ebf0 Ansible user home in /home 2026-06-22 16:45:33 +02:00
Fabio Sinibaldi eec3cc677f Merge pull request 'next_migration' (#9) from next_migration into main
Reviewed-on: #9
2026-06-22 16:42:27 +02:00
Fabio Sinibaldi b1a19a374c Added vpn-1 server e dev-1 2026-06-22 16:30:57 +02:00
Fabio Sinibaldi 954a6c3562 Added vpn-1 server e dev-1 2026-06-22 16:29:59 +02:00
Fabio Sinibaldi 16309ca46f added lucio 2026-06-22 16:28:58 +02:00
Fabio Sinibaldi e0b7533bec Merge pull request 'next_migration' (#8) from next_migration into main
Reviewed-on: #8
2026-06-19 16:10:06 +02:00
Fabio Sinibaldi 57eeda2a52 Make Apache listen to 443 2026-06-19 16:07:15 +02:00
Fabio Sinibaldi 8b4d7737e1 wireguard key fabio 2026-06-19 16:06:58 +02:00
Fabio Sinibaldi dd585233e2 inventory update 2026-06-19 16:06:39 +02:00
Fabio Sinibaldi e320843d5a Fixed N Aio image tag and name 2026-06-16 12:04:56 +02:00
Fabio Sinibaldi 84b509ec37 Nextcloud AIO 2026-06-15 16:49:01 +02:00
Fabio Sinibaldi e3c1b4082e Merge pull request 'automotive' (#7) from automotive into main
Reviewed-on: #7
2026-06-12 11:15:33 +02:00
Fabio Sinibaldi 5bef64c3c0 fix paths 2026-06-04 09:41:44 +02:00
Fabio Sinibaldi 525fc50429 clean defaults file 2026-06-04 09:41:02 +02:00
Fabio Sinibaldi d5698f4be6 requirements for wireguard role 2026-06-04 09:40:16 +02:00
Fabio Sinibaldi 256fdc5b58 Merge pull request 'automotive' (#6) from automotive into main
Reviewed-on: #6
2026-06-04 09:29:56 +02:00
21 changed files with 325 additions and 126 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.DS_Store
ansible/playbooks/wg_clients

View File

@ -1,5 +1,9 @@
---
externals:
children:
nextcloud:
hosts:
c-service.sse.cloud.isti.cnr.it
rup_tests:
hosts:
liquid:

View File

@ -2,11 +2,28 @@
wg_interface: wg0
wg_port: 51820
#wg_server_public_interface: eth0
wg_server_address: 192.168.99.1/32
wg_server_address: 192.168.98.1/32
#wg_server_private_key: "{{ wg_server_private_key }}"
wg_peers:
- name: fabio_test
publicKey: "dzODOKndtafZSf2GqvClFdxrpwyNJnZ/AsZkNl+ovEE="
allowedIP: "192.168.99.4/32"
- name: fabio
ip: "192.168.98.11/32"
allowedIPs :
- "192.168.98.0/24"
- "10.22.0.0/16"
- name: lucio
ip: "192.168.98.12/32"
allowedIPs :
- "192.168.98.0/24"
- "10.22.0.0/16"
- name: roberto
ip: "192.168.98.13/32"
allowedIPs :
- "192.168.98.0/24"
- "10.22.0.0/16"
- name: giorgio
ip: "192.168.98.14/32"
allowedIPs :
- "192.168.98.0/24"
- "10.22.0.0/16"

View File

@ -0,0 +1,26 @@
---
wg_interface: wg0
wg_port: 51820
#wg_server_public_interface: eth0
wg_server_address: 192.168.99.1/32
#wg_server_private_key: "{{ wg_server_private_key }}"
wg_peers:
- name: fabio_test
publicKey: "9a3tgXpF5CAOffbHZdW1QBEJgSLFnBDVbD1JaMPgzkM="
ip: "192.168.99.4/32"
allowedIPs :
- "192.168.99.0/24"
- "10.22.0.0/16"
- name: missing_key_test
ip: "192.168.99.5/32"
allowedIPs :
- "192.168.99.0/24"
- "10.22.0.0/16"
- name: forced_missing_key_test
forceRegeneration: True
ip: "192.168.99.6/32"
allowedIPs :
- "192.168.99.0/24"
- "10.22.0.0/16"

View File

@ -2,22 +2,22 @@
# SIFI
sifi:
children:
opn:
hosts:
sifi_opnsense.sifi.isti.cnr.it:
#opn:
#hosts:
# sifi_opnsense.sifi.isti.cnr.it:
# ns1.sifi.isti.cnr.it:
# ansible_host: 146.48.108.51 #[WAN public ip]
# ansible_host: 10.20.30.111
wireguard_server:
hosts:
wireguarder.sifi.isti.cnr.it:
vpn-1.sifi.sse.cloud.isti.cnr.it:
# ansible_host: 146.48.108.13
nameserver:
hosts:
ns1.sifi.isti.cnr.it:
ansible_host: 146.48.108.51
# nameserver:
# hosts:
#ns1.sifi.isti.cnr.it:
# ansible_host: 146.48.108.51
# dns1.internal.sifi.isti.cnr.it:
# ansible_host: 10.11.12.11
workers:
hosts:
worker1.internal.sifi.isti.cnr.it:
dev-1.sifi.sse.cloud.isti.cnr.it:

View File

@ -0,0 +1,15 @@
---
vlab-1:
children:
yuno:
hosts:
yuno.sse.cloud.isti.cnr.it:
wireguard_server:
hosts:
vpn-1.sse.cloud.isti.cnr.it:
nextcloud:
hosts:
b-service_2:
ansible_host: 10.22.2.77
b-service_1:
ansible_host: 10.22.1.145

View File

@ -1,17 +1,8 @@
---
- name: Install Nextcloud AIO Docker
hosts: all
hosts: nextcloud
become: true
vars:
pip_install_packages:
- name: docker
docker_version: "=5:28.2.2-1~ubuntu.24.04~noble"
docker_users:
- fabio
- ansible
roles:
- geerlingguy.pip
- geerlingguy.docker
# - nextcloud_aio
- nextcloud_aio

View File

@ -1,3 +1,3 @@
#SPDX-License-Identifier: MIT-0
---
# defaults file for docker
docker_version: "*.*.*"
docker_sudo_users: []

View File

@ -0,0 +1,4 @@
nextcloud_docker_image_name: "ghcr.io/nextcloud-releases/all-in-one"
nextcloud_docker_image_tag: latest
nextcloud_docker_skip_domain_validation: "true"
nextcloud_docker_mastercontainer_volume_dir: /usr/data/nextcloud_aio_mastercontainer

View File

@ -1,2 +0,0 @@
dependencies:
- role: docker

View File

@ -1,18 +1,31 @@
---
- name: Create volumes
debug:
msg:
- "TODO!!!"
- name: Pull docker image
docker_image:
name: "{{ nextcloud_docker_image_name }}"
tag: "{{ nextcloud_docker_image_tag }}"
source: pull
- name: Download compose file
become: true
become_user: docker
ansible.builtin.git:
repo: "https://gitea-s2i2s.isti.cnr.it/sinibaldi/SSE-Lab"
dest: SSE-Lab
- name: Create Master Container volume dir
file:
path: "{{ nextcloud_docker_mastercontainer_volume_dir }}"
state: directory
mode: "0766"
- name: create and start docker compose services
become: true
become_user: docker
community.docker.docker_compose_v2:
project_src: ~/SSE-Lab/dockerized/nextcloud-aio/compose.yaml
- name: Create container
docker_container:
name: nextcloud-aio-mastercontainer
image: "{{ nextcloud_docker_image_name }}"
ports:
- "8080:8080"
- "80:80"
- "8443:8443"
env:
APACHE_PORT: "443"
APACHE_IP_BINDING: "0.0.0.0"
APACHE_ADDITIONAL_NETWORK: ""
SKIP_DOMAIN_VALIDATION: "{{ nextcloud_docker_skip_domain_validation }}"
volumes:
- nextcloud_aio_mastercontainer:/mnt/docker-aio-config
- /var/run/docker.sock:/var/run/docker.sock:ro
restart_policy : "always"
init : true

View File

@ -0,0 +1,20 @@
---
- name: Check if config already exists
stat:
path: "/etc/wireguard/{{ wg_interface }}.conf"
register: interface_configuration
- name: Parse configuration
ansible.utils.cli_parse:
command: "cat /etc/wireguard/{{ wg_interface }}.conf "
parser:
name: ansible.netcommon.native
template_path: templates/wg_config_template.yaml
set_fact: existing_wg_config
when: interface_configuration.stat.exists
- name: Updating client configs info
set_fact:
wg_peers: "{{ wg_peers | community.general.lists_mergeby([{'name':item.key,'publicKey':item.value.publicKey}] ,'name')}}"
when: item.key in (wg_peers | map(attribute='name'))
loop: "{{ existing_wg_config | ansible.builtin.dict2items }}"

View File

@ -0,0 +1,67 @@
---
- name: Init generated Keys dict
set_fact:
generated_keys: []
- name : Gather needed key generation
set_fact:
generated_keys: "{{ generated_keys + [{'name': item.name}] }}"
when : item.publicKey is not defined or (item.forceRegeneration is defined and item.forceRegeneration)
loop: "{{ wg_peers }}"
- name : Generate private keys
command : wg genkey
register: privateKeyObjects
loop : "{{ generated_keys }}"
- name : Generate public keys
shell : echo "{{privateKeyObjects.results[ansible_loop.index0].stdout}}" | wg pubkey
register: publicKeyObjects
loop : "{{ generated_keys }}"
loop_control:
extended: true
- name: Registering generated keys
set_fact:
generated_keys: "{{ generated_keys | community.general.lists_mergeby ([{'privateKey' : privateKeyObjects.results[ansible_loop.index0].stdout, 'publicKey' : publicKeyObjects.results[ansible_loop.index0].stdout, 'name':item.name }],'name') }}"
loop: "{{ generated_keys }}"
loop_control:
extended: true
- name: Updating client configs info
set_fact:
wg_peers: "{{ wg_peers | community.general.lists_mergeby(generated_keys,'name')}}"
- name: Delete local configs directory
become: false
local_action : ansible.builtin.file
args:
path: "{{ playbook_dir }}/wg_clients/{{ inventory_hostname }}"
state: absent
- name: Re-create local configs directory
become: false
local_action : ansible.builtin.file
args:
path: "{{ playbook_dir }}/wg_clients/{{ inventory_hostname }}"
state: directory
mode: '0700'
- name : Generate client config file
become: false
local_action : ansible.builtin.template
args:
src: templates/wireguard_client.jinja
dest: "{{ playbook_dir }}/wg_clients/{{ inventory_hostname }}/{{ item.name }}.conf"
vars:
wg_client_public_key: "{{ item.publicKey }}"
wg_client_private_key: "{{ item.privateKey | default('')}}"
wg_client_address: "{{ item.ip }}"
allowed_ips : "{{ item.allowedIPs }}"
wg_server : "{{ inventory_hostname }}"
loop: "{{ wg_peers }}"

View File

@ -6,39 +6,39 @@
state: directory
mode: '0700'
- name: Check if private key already exists
- name: Check if server private key already exists
ansible.builtin.stat:
path: /etc/wireguard/privatekey
register: privkey_file
register: privatekey_file
- name: Generate private key
- name: Generate server private key
ansible.builtin.command: wg genkey
register: wg_private_key
when: not privkey_file.stat.exists
when: not privatekey_file.stat.exists
changed_when: true
- name: Save private key
- name: Save server private key
ansible.builtin.copy:
content: "{{ wg_private_key.stdout }}"
dest: /etc/wireguard/privatekey
owner: root
group: root
mode: '0600'
when: not privkey_file.stat.exists
when: not privatekey_file.stat.exists
- name: Read private key
- name: Read server private key
ansible.builtin.slurp:
src: /etc/wireguard/privatekey
register: private_key_content
- name: Generate public key from private key
- name: Generate server public key from private key
ansible.builtin.shell: echo "{{ private_key_content.content | b64decode | trim }}" | wg pubkey
register: wg_public_key
register: wg_server_public_key
changed_when: false
- name: Save public key
- name: Save server public key
ansible.builtin.copy:
content: "{{ wg_public_key.stdout }}"
content: "{{ wg_server_public_key.stdout }}"
dest: /etc/wireguard/publickey
owner: root
group: root
@ -46,4 +46,4 @@
- name: Display public key for reference
ansible.builtin.debug:
msg: "Public key for {{ inventory_hostname }}: {{ wg_public_key.stdout }}"
msg: "Public key for {{ inventory_hostname }}: {{ wg_server_public_key.stdout }}"

View File

@ -1,4 +1,6 @@
---
- include_tasks: install_wireguard.yaml
- include_tasks: generate_keys.yaml
- include_tasks: gather_current_config.yaml
- include_tasks: generate_server_keys.yaml
- include_tasks: generate_client_configs.yaml
- include_tasks: configure_server.yaml

View File

@ -1,62 +0,0 @@
---
- name: Install Wireguard Server
apt:
pkg:
- wireguard
state: latest
update_cache: true
- name: Create directory for wg keys
ansible.builtin.file:
path: /etc/wireguard/keys
state: directory
mode: '0755'
- name: Creating server privatekey and publickey
shell: wg genkey | tee privatekey | wg pubkey > publickey
args:
chdir: /etc/wireguard/keys
- name: Get Private Key [privatekey => var_privatekey]
shell: cat privatekey
register: var_privatekey
args:
chdir: /etc/wireguard/keys
#- name: Add WireGuard interface
# command: ip link add dev wg0 type wireguard
- name: Updating configuration
template:
src: wireguard_server.jinja
dest: /etc/wireguard/wg0.conf
#- name: Activating link
# command: ip link set up dev wg0
- name: Starting wg service
systemd:
state: started
name: wg-quick@wg0
enabled: yes
- name: Getting public key
shell: cat publickey
register: var_publickey
args:
chdir: /etc/wireguard/keys
- name: Check server public IP
shell: curl https://ipinfo.io/ip
register: var_server_ip
- name: Printing public key
debug:
msg: "Server {{ ansible_hostname }} reachable @{{var_server_ip}}. Public key is {{ var_publickey }}"

View File

@ -0,0 +1,13 @@
---
- example: "# Peer ID : fabio_test"
getval: '# Peer ID : (?P<peer_id>\S+)'
result:
"{{ peer_id }}":
name: "{{ peer_id }}"
shared: true
- example: "PublicKey = 9a3tgXpF5CAOffbHZdW1QBEJgSLFnBDVbD1JaMPgzkM="
getval: 'PublicKey = (?P<publicKey>\S+)'
result:
"{{ peer_id }}":
publicKey: "{{ publicKey }}"

View File

@ -0,0 +1,18 @@
[Interface]
{% if wg_client_private_key is defined and wg_client_private_key != None and wg_client_private_key != ''%}
PrivateKey = {{wg_client_private_key}}
{% else%}
# Public and private keys were pre generated by client
# Insert private key below and uncomment in order to use the present configuration
# PrivateKey =
{% endif %}
Address = {{wg_client_address}}
[Peer]
PublicKey = {{wg_server_public_key.stdout}}
AllowedIPs = {{ allowed_ips | join(', ') }}
Endpoint = {{ wg_server }}:{{ wg_port }}
PersistentKeepalive = 25

View File

@ -16,10 +16,10 @@ PostDown = iptables -t nat -D POSTROUTING ! -o {{wg_interface}} -m mark --mark 0
{% for peer in wg_peers %}
# {{ peer.name }}
# Peer ID : {{ peer.name }}
[Peer]
PublicKey = {{ peer.publicKey }}
AllowedIPs = {{ peer.allowedIP }}
AllowedIPs = {{ peer.ip }}
{% if peer.persistent_keepalive is defined %}
PersistentKeepalive = {{ peer.persistent_keepalive }}
{% endif %}

View File

@ -37,11 +37,15 @@ Calls role nextcloud_aio, dependent on docker role.
- Downloads SSE-Lab Repo
- Runs compose up (using ansible plugins)
E.g. `ansible-playbook -i inventories/ -l nextrup_copy_test playbooks/nextcloud.yaml`
E.g.
```ansible-playbook -i inventories/ -l nextrup_copy_test playbooks/nextcloud.yaml```
### Bootstrap ###
Creates sudoer user ansible, necessitates of sudoer user.
Use `ansible-playbook -i inventories playbooks/bootstrap.yml -l [TARGET_HOST] -e 'ansible_user=[REMOTE_USER]' -K`
Use
```ansible-playbook -i inventories playbooks/bootstrap.yml -l [TARGET_HOST] -e 'ansible_user=[REMOTE_USER]' -K```
### NameServer ###
@ -56,8 +60,72 @@ Configures a OPNSense edge node features :
- Wireguard VPN
NB runs locally so python intepreter needs to be specified
E.g. `ansible-playbook -i inventories/sifi.yaml playbooks/opnsense.yaml --extra-vars="ansible_python_interpreter=$(which python)"
`
E.g.
```ansible-playbook -i inventories/sifi.yaml playbooks/opnsense.yaml --extra-vars="ansible_python_interpreter=$(which python)"
```
### VPN Server ###
Configures a VPN Server (only wireguard supported at the moment) for the specified 'wg_peers'.
The server acts as a gateway into a site, tunneling each connection and allowing only traffic into allowed subnets.
Needed parameters and configuration example :
```
wg_interface: wg0
wg_port: 51820
wg_server_address: 192.168.99.1/32
wg_peers:
- name: fabio_test
publicKey: "9a3tgXpF5CAOffbHZdW1QBEJgSLFnBDVbD1JaMPgzkM="
ip: "192.168.99.4/32"
allowedIPs :
- "192.168.99.0/24"
- "10.22.0.0/16"
- name: missing_key_test
ip: "192.168.99.5/32"
allowedIPs :
- "192.168.99.0/24"
- "10.22.0.0/16"
- name: forced_missing_key_test
forceRegeneration: True
ip: "192.168.99.6/32"
allowedIPs :
- "192.168.99.0/24"
- "10.22.0.0/16"
```
#### Wg-peers items ####
Each item represents a client [**Peer**] with :
- *name* [**Mandatory**] : a unique label for the client configuration
- *publicKey*: public key used by the client. If missing, the playbook generates both public and private keys, if needed.
- *ip* [**Mandatory**]: reserved ip for the client
- *allowedIPs* [**Mandatory**]: subnets to which the server allows traffic to for the present client
- *forceRegeneration*: force regeneration of public / private keys pair.
#### Client configurations ####
The playbook generates client configurations at the following path
> "{{ playbook_dir }}/wg_clients/{{ inventory_hostname }}/{{ item.name }}.conf"
**NB** Client configurations are ready to be imported in wireguard client if the playbook generated both public and private keys. Otherwise only the client's public key is reported and the user is expected to fill the configuration properly with their private key.
#### Key pair generation policy ####
In order to configure peers to connect to the server, public/private key pairs are needed.
The playbook evalutes the need for key generation as following :
- If *forceRegeneration* is set to *True*, keys are generated
- If *publicKey* is declared, that key is used
- If a public Key is already configured on the server for that Peer's name, that key is used
- If no public key is declared nor found, a new private / public key pair is generated and reported in client's configuration
## Inventories

View File

@ -1,6 +1,10 @@
# requirements.yml
---
roles:
- name: githubixx.ansible_role_wireguard
src: https://github.com/githubixx/ansible-role-wireguard.git
version: 19.0.0
# - name: bodsch.dns.bind
# version: