wgvirtipd/dev/setup.yaml

62 lines
1.8 KiB
YAML
Raw Normal View History

2024-01-17 21:48:47 +01:00
---
- name: Wireguard config generator
hosts: localhost
vars:
mask_bits: 24
base_ip: 10.2.0.0
port: 51871
keepalived_ip: 10.2.0.100
2024-01-17 21:48:47 +01:00
tasks:
- name: generate keypair
shell: |
#!/bin/sh
priv="$(wg genkey)"
pub="$(echo "$priv" | wg pubkey)"
base_ip="{{ base_ip }}"
my_ip="$(echo "$base_ip" | sed 's/0$/{{ item }}/')"
if [[ {{item}} -eq 1 ]]; then
state=MASTER
else
state=BACKUP
fi
priority=$((100 - {{ item }}))
2024-01-17 21:48:47 +01:00
jq --null-input \
--arg priv "$priv" \
--arg pub "$pub" \
--arg my_ip "$my_ip" \
--arg state "$state" \
--arg priority "$priority" \
'{"private_key": $priv, "public_key": $pub, "item": "vm{{ item }}", "ip": $my_ip, "keepalived_state": $state, "keepalived_priority": $priority}'
2024-01-17 21:48:47 +01:00
with_items: ["1", "2", "3", "4"]
register: keypairs_
- set_fact:
keypairs: "{{ keypairs | default([]) + [item.stdout | from_json] }}"
with_items: "{{ keypairs_.results }}"
- debug:
var: keypairs
name: write wg configs
- template:
src: ./config/wg0.conf.tmpl
dest: ./config/{{ item.item }}-wg0.conf
with_items: "{{ keypairs }}"
- template:
src: ./config/keepalived.conf.tmpl
dest: ./config/{{ item.item }}-keepalived.conf
with_items: "{{ keypairs }}"
2024-01-22 16:34:28 +01:00
- template:
src: ./config/lighttpd.conf.tmpl
dest: ./config/{{ item.item }}-lighttpd.conf
with_items: "{{ keypairs }}"
- template:
src: ./config/index.html.tmpl
dest: ./config/{{ item.item }}-index.html
with_items: "{{ keypairs }}"
2024-01-22 16:34:28 +01:00
- template:
src: ./config/wgvirtipd.sh.tmpl
dest: ./config/{{ item.item }}-wgvirtipd.sh
mode: 0755
with_items: "{{ keypairs }}"
2024-01-17 21:48:47 +01:00
- template:
src: ./docker-compose.yaml.tmpl
dest: ./docker-compose.yaml