infra/roles/tunnel/tasks/tunnel.yml

49 lines
1.0 KiB
YAML

---
- name: install autossh
apt:
name: autossh
state: present
tags:
- autossh
- packages
- name: template tunnel keys
template:
src: "private/sshkeys/{{ item }}"
dest: /home/.system/tunnel/.ssh/{{ item }}
owner: tunnel
group: tunnel
mode: 0700
with_items:
- tunnel
- tunnel.pub
- name: template tunnel authorized_keys and known hosts
template:
src: private/sshkeys/tunnel.{{ item }}
dest: /home/.system/tunnel/.ssh/{{ item }}
owner: tunnel
group: tunnel
mode: 0700
with_items:
- authorized_keys
- known_hosts
- name: set up autossh tunnels systemd services
template:
src: autossh.service.j2
dest: /etc/systemd/system/autossh-{{ item.hostname }}.service
with_items: "{{ ssh_tunnels }}"
notify:
- systemctl daemon reload
- restart autossh
- name: start and enable authssh tunnels
service:
name: autossh-{{ item.hostname }}
enabled: true
state: started
with_items: "{{ ssh_tunnels }}"
when: not ansible_check_mode