From 8ff8f1fa4037defebab29c7c7775ae3372cbe9a7 Mon Sep 17 00:00:00 2001 From: binary Date: Sat, 7 Nov 2020 20:39:07 +0100 Subject: Automate network deployment --- roles/ssh/tasks/generate_dns.yml | 1 + roles/ssh/tasks/main.yml | 6 ++++++ roles/ssh/templates/generate_dns.j2 | 27 +++++++++++++++++++-------- 3 files changed, 26 insertions(+), 8 deletions(-) (limited to 'roles/ssh') diff --git a/roles/ssh/tasks/generate_dns.yml b/roles/ssh/tasks/generate_dns.yml index 6501299..60a21bd 100644 --- a/roles/ssh/tasks/generate_dns.yml +++ b/roles/ssh/tasks/generate_dns.yml @@ -5,3 +5,4 @@ template: src: templates/generate_dns.j2 dest: "{{ lookup('env', 'HOME') }}/.ssh/config.d/ssh_dns" + delegate_to: 127.0.0.1 diff --git a/roles/ssh/tasks/main.yml b/roles/ssh/tasks/main.yml index e69de29..38300df 100644 --- a/roles/ssh/tasks/main.yml +++ b/roles/ssh/tasks/main.yml @@ -0,0 +1,6 @@ + +# ssh ~~ tasks/main.yml + +--- + +- include: generate_dns.yml diff --git a/roles/ssh/templates/generate_dns.j2 b/roles/ssh/templates/generate_dns.j2 index c8d5a44..59c6233 100644 --- a/roles/ssh/templates/generate_dns.j2 +++ b/roles/ssh/templates/generate_dns.j2 @@ -1,13 +1,24 @@ -{% for host in groups["servers"] %} -{% set host = hostvars[host] %} -Match originalhost dcontroller exec "systemctl is-active wg-quick@{{ _i.dcontroller }}.service" - HostName {{ host.ip.inbound }} - Port {{ host.services.tcp.ssh }} +# ssh configuration for dns ~~ ~/.ssh/.config.d/ +# managed by Ansible -Match originalhost {{ host.ansible_host }} - HostName {{ host.ip.outbound }} - Port {{ host.services.tcp.ssh }} +{% for h in groups["all"] %} +{% set h = hostvars[h] %} +{##} +{% if h.ip is defined %} +{% set _port = h.services | selectattr("name", "equalto", "ssh") | map(attribute="port") | list | join(' ') %} +{##} +# {{ h.ansible_host }} + +Match originalhost {{ h.ansible_host }} exec "systemctl is-active wg-quick@{{ _i.dcontroller }}.service" + HostName {{ h.ip.in }} + Port {{ _port }} + +Match originalhost {{ h.ansible_host }} + HostName {{ h.ip.out }} + Port {{ _port }} User root +{% endif %} +{##} {% endfor %} -- cgit v1.2.3