diff options
Diffstat (limited to 'roles/_workstation/sshdns')
-rw-r--r-- | roles/_workstation/sshdns/defaults/main.yml | 3 | ||||
-rw-r--r-- | roles/_workstation/sshdns/tasks/main.yml | 17 | ||||
-rw-r--r-- | roles/_workstation/sshdns/templates/sshdns.j2 | 20 |
3 files changed, 40 insertions, 0 deletions
diff --git a/roles/_workstation/sshdns/defaults/main.yml b/roles/_workstation/sshdns/defaults/main.yml new file mode 100644 index 0000000..9427f1d --- /dev/null +++ b/roles/_workstation/sshdns/defaults/main.yml @@ -0,0 +1,3 @@ +--- + +sshdns_waittime: 2 diff --git a/roles/_workstation/sshdns/tasks/main.yml b/roles/_workstation/sshdns/tasks/main.yml new file mode 100644 index 0000000..daf8f61 --- /dev/null +++ b/roles/_workstation/sshdns/tasks/main.yml @@ -0,0 +1,17 @@ +--- + +- name: create config directory + file: + path: '/home/{{ _ws_user }}/.ssh/config.d' + state: directory + group: '{{ _ws_user }}' + owner: '{{ _ws_user }}' + mode: '0700' + +- name: generate template to localhost + template: + src: templates/sshdns.j2 + dest: '/home/{{ _ws_user }}//.ssh/config.d/ssh_dns' + owner: '{{ _ws_user }}' + group: '{{ _ws_user }}' + mode: '0600' diff --git a/roles/_workstation/sshdns/templates/sshdns.j2 b/roles/_workstation/sshdns/templates/sshdns.j2 new file mode 100644 index 0000000..1778215 --- /dev/null +++ b/roles/_workstation/sshdns/templates/sshdns.j2 @@ -0,0 +1,20 @@ +{% import 'macros.j2' as macros with context %} + +# ssh configuration for dns ~~ ~/.ssh/.config.d/ +# managed by Ansible + +{% set dcontroller = hostvars[global.dcontroller] %} +{% call(h) macros.loop_hosts("servers") %} +{% if h.ip is defined and h.services is defined %} +{% set _port = h.services | selectattr("name", "equalto", "ssh") | map(attribute="port") | list | join(' ') %} +# {{ h.ansible_host }} +Match originalhost {{ h.ansible_host }} exec "ping -c 1 -w {{ sshdns_waittime }} {{ dcontroller.ip.in }} && ! ping -c 1 -w {{ sshdns_waittime }} {{ h.ip.out }}" + HostName {{ h.ip.in }} + Port {{ _port }} +Match originalhost {{ h.ansible_host }} + HostName {{ h.ip.out }} + Port {{ _port }} + User root + +{% endif %} +{% endcall %} |