diff options
author | Romain Gonçalves <me@rgoncalves.se> | 2021-12-05 13:07:49 +0000 |
---|---|---|
committer | Romain Gonçalves <me@rgoncalves.se> | 2021-12-05 21:03:22 +0000 |
commit | a0dd74445b4460e5e7fa4c72bd478348eb960224 (patch) | |
tree | f8887dff286c7d39c8c49c62e2969d87a4235f0e /roles/workstation | |
parent | 28c76a43c348456af3d1508c88c73edaa059735c (diff) | |
download | rules-a0dd74445b4460e5e7fa4c72bd478348eb960224.tar.gz |
roles/workstation: Generate hostnames for ssh
Diffstat (limited to 'roles/workstation')
-rw-r--r-- | roles/workstation/tasks/main.yml | 11 | ||||
-rw-r--r-- | roles/workstation/tasks/ssh.yml | 18 | ||||
-rw-r--r-- | roles/workstation/templates/ssh.config.j2 | 11 |
3 files changed, 40 insertions, 0 deletions
diff --git a/roles/workstation/tasks/main.yml b/roles/workstation/tasks/main.yml index c20b81b..87f6188 100644 --- a/roles/workstation/tasks/main.yml +++ b/roles/workstation/tasks/main.yml @@ -32,3 +32,14 @@ file: smartcard.yml apply: tags: task_smartcard + +- name: include ssh setup + tags: always + include_tasks: + file: ssh.yml + apply: + tags: task_ssh + args: + apply: + become: true + become_user: "{{ workstation_user }}" diff --git a/roles/workstation/tasks/ssh.yml b/roles/workstation/tasks/ssh.yml new file mode 100644 index 0000000..318198e --- /dev/null +++ b/roles/workstation/tasks/ssh.yml @@ -0,0 +1,18 @@ +- name: create ssh directory + file: + path: "/home/{{ workstation_user }}/{{ item }}" + owner: "{{ workstation_user }}" + group: "{{ workstation_user }}" + state: directory + mode: 0700 + loop: + - .ssh + - .ssh/config.d + +- name: generate ssh configuration + template: + src: ssh.config.j2 + dest: "/home/{{ workstation_user }}/.ssh/config.d/dns.config" + owner: "{{ workstation_user }}" + group: "{{ workstation_user }}" + mode: 0600 diff --git a/roles/workstation/templates/ssh.config.j2 b/roles/workstation/templates/ssh.config.j2 new file mode 100644 index 0000000..2915a1a --- /dev/null +++ b/roles/workstation/templates/ssh.config.j2 @@ -0,0 +1,11 @@ +# managed by Ansible +{% import 'macros.j2' as macros with context %} + +{% call(h) macros.loop_valid_hosts("all") %} +{% set command = "pgrep wg && ! ping -c 1 -w 1 %s" % h.__ip.external %} +Match originalHost {{ h.inventory_hostname }} exec "{{ command }}" + HostName {{ h.__ip.internal }} +Match originalHost {{ h.inventory_hostname }} + HostName {{ h.__ip.external }} + +{% endcall %} |