1 Commits

Author SHA1 Message Date
8455a0e2d0 testing 2023-07-23 18:46:40 -04:00
4 changed files with 47 additions and 30 deletions

View File

@@ -1,8 +0,0 @@
- name: Install Docker Server
hosts: all
become: true
vars_files:
- host_vars/docker.yml
roles:
- base
- docker

View File

@@ -1,13 +0,0 @@
# base
allow_reboot: false
manage_network: false
# docker
docker_users:
- vagrant
docker_compose_deploy:
- name: docs
url: git@git.krislamo.org:kris/homelab-docs.git
version: main
sync: true

View File

@@ -53,21 +53,13 @@
loop: "{{ docker_compose_deploy }}"
when: docker_compose_deploy is defined
- name: Copy docker-compose project directory
ansible.builtin.copy:
src: "{{ docker_repos_path }}/{{ item.name }}/"
dest: "{{ docker_compose_root }}/{{ item.name }}/"
remote_src: yes
loop: "{{ docker_compose_deploy }}"
when: docker_compose_deploy is defined and item.sync | default(false)
- name: Copy docker-compose.yml files to their service directories
ansible.builtin.copy:
src: "{{ docker_repos_path }}/{{ item.name }}/{{ item.path | default('docker-compose.yml') }}"
dest: "{{ docker_compose_root }}/{{ item.name }}/docker-compose.yml"
remote_src: yes
loop: "{{ docker_compose_deploy }}"
when: docker_compose_deploy is defined and not item.sync | default(false)
when: docker_compose_deploy is defined
- name: Set environment variables for docker-compose projects
ansible.builtin.template:

46
run-proxy.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/bash
# Find private key file
PRIVATE_KEY="$(find .vagrant -name "private_key")"
# Does the private_key file exist?
if [ ! -f "$PRIVATE_KEY" ]; then
echo "[ERROR] File not found at \"$PRIVATE_KEY\""
exit 1
fi
# Is the private_key a valid SSH key?
echo "Checking validity of private key at $(pwd)/$PRIVATE_KEY"
if ! ssh-keygen -l -f "$PRIVATE_KEY"; then
echo "[Error] The private key at \"$PRIVATE_KEY\" is invalid (CODE: $?)"
exit 1
fi
# Find an IP on the VM for the SSH tunnel
HOST_IP="$(vagrant ssh -c "hostname -I | cut -d' ' -f${HOSTNAME_FIELD:-1}" 2>/dev/null | sed 's/.$//')"
# SSH command to match in processes table
CMD="ssh -fNT -i $PRIVATE_KEY -L 8443:localhost:8443 -L 80:localhost:80 -L 443:localhost:443.*vagrant@$HOST_IP"
# Not just after PIDs
# shellcheck disable=SC2009
PS_TUNNELS="$(ps aux | grep -e "$CMD" | grep -v grep)"
PS_COUNTER="$(echo "$PS_TUNNELS" | wc -l)"
if [ "$PS_COUNTER" -gt 0 ]; then
echo "[ERROR] Tunnel(s) already seems to exist (counted $PS_COUNTER)"
echo \""$PS_TUNNELS"\"
exit 1
fi
# Create an SSH tunnel
echo "Starting background SSH connection for localhost port forwarding"
set -x
ssh -fNT -i "$PRIVATE_KEY" \
-L 8443:localhost:8443 \
-L 80:localhost:80 \
-L 443:localhost:443 \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
vagrant@"${HOST_IP}" 2>/dev/null