Files
env-ansible/tasks/general/settings/tunnel.yml
T

75 lines
2.2 KiB
YAML

---
# 2026-10-17 Hyperling
# Allow pushing a local port to a remote server automagically in a runit script.
# ssh -N -p SSH_PORT -R REMOTE_PORT:localhost:LOCAL_PORT USER@REMOTE_HOST -v
- name: General | Tunnel | Provisioned Variables
ansible.builtin.debug:
var: "{{ item }}"
loop:
- tunnel_local_port
- tunnel_remote_host
- tunnel_remote_port
- tunnel_ssh_port
- name: General | Tunnel | Block
block:
- name: General | Tunnel | Facts
ansible.builtin.set_fact:
tunnel_service_name: tunnel
- name: General | Tunnel | mkdir | /etc/sv
ansible.builtin.file:
path: /etc/sv/{{ tunnel_service_name }}/log
state: directory
mode: "0755"
- name: General | Tunnel | mkdir | /var/log
ansible.builtin.file:
path: /var/log/{{ tunnel_service_name }}
state: directory
mode: "0755"
- name: General | Tunnel | Script | Run
ansible.builtin.copy:
dest: /etc/sv/{{ tunnel_service_name }}/run
content: |
#!/bin/sh -e
exec 2>&1
exec chpst -u {{ user }} ssh -v -H \
-R {{ tunnel_remote_port }}:localhost:{{ tunnel_local_port }} \
-p {{ tunnel_ssh_port }} {{ tunnel_remote_host }}
mode: "0755"
- name: General | Tunnel | Script | Finish
ansible.builtin.copy:
dest: /etc/sv/{{ tunnel_service_name }}/finish
content: |
{{ runit_finish_sleep }}
mode: "0755"
- name: General | Tunnel | Script | Log
ansible.builtin.copy:
dest: /etc/sv/{{ tunnel_service_name }}/log/run
content: |
#!/bin/sh -e
exec svlogd -tt /var/log/{{ tunnel_service_name }}
mode: "0755"
- name: General | Tunnel | Script | Log Config
ansible.builtin.copy:
dest: /var/log/{{ tunnel_service_name }}/config
content: |
{{ runit_log_config_10mb }}
mode: "0755"
when: tunnel_remote_host != "false"
- name: General | Tunnel | Service | Enable
ansible.builtin.service:
name: "{{ tunnel_service_name }}"
state: "{{ 'started' if tunnel_remote_host else 'stopped' }}"
enabled: "{{ true if tunnel_remote_host else false }}"