|
1 | 1 | {% set ssh_defaults = defaults.ssh|default({}) %} |
2 | 2 | {% set hostname = ssh_defaults.hostname|default('netlab') %} |
3 | | -{% set public_ip = ssh_defaults.publicip|default('127.0.0.1') %} |
| 3 | +{% set public_ip = ssh_defaults.publicip|default('') %} |
4 | 4 | {% set netlab_path = ssh_defaults.netlabpath|default('netlab') %} |
| 5 | +{% set ssh_conn = ['paramiko','netconf','paramiko_ssh','network_cli'] %} |
5 | 6 | # |
6 | 7 | # This SSH configuration file allows you to connect to netlab devices running |
7 | 8 | # on a remote server straight from your workstation |
|
11 | 12 | # |
12 | 13 | # You can change the SSH parameters with these environment variables |
13 | 14 | # |
14 | | -# NETLAB_SSH_HOSTNAME The hostname used for port forwarding (not implemented yet) |
15 | | -# NETLAB_SSH_PUBLICIP The IP address or hostname of the netlab server |
| 15 | +# NETLAB_SSH_HOSTNAME The hostname of the netlab server |
| 16 | +# NETLAB_SSH_PUBLICIP The IP address of the netlab server when the hostname is not resolvable |
16 | 17 | # NETLAB_SSH_NETLABPATH The path to 'netlab' command (if it's not in PATH) |
17 | 18 | # |
18 | 19 | Host {{ hostname }} |
| 20 | + StrictHostKeyChecking off |
| 21 | + UserKnownHostsFile /dev/null |
| 22 | +{% if public_ip %} |
19 | 23 | HostName {{ public_ip }} |
20 | | -{# for host in groups['fortios'] %} |
21 | | -{% set hv = hostvars[host] %} |
22 | | -{% if hv.get('provider') != 'clab' %} |
23 | | - LocalForward {{ 8000 + hv.id }} {{ hv.ansible_host }}:443 |
24 | | -{% endif %} |
25 | | -{% endfor #} |
| 24 | +{% endif %} |
| 25 | +{% for provider in defaults.providers.keys() %} |
| 26 | +{% for n_name,n_data in nodes.items() if provider in n_data and 'ports' in n_data[provider] %} |
| 27 | +{% for p_fwd in n_data[provider].ports %} |
| 28 | +{% set p_data = p_fwd.split(':') %} |
| 29 | + LocalForward {{ p_data[0] }} {{ n_data.ansible_host }}:{{ p_data[1] }} |
| 30 | +{% endfor %} |
| 31 | +{% endfor %} |
| 32 | +{% endfor %} |
26 | 33 |
|
27 | 34 | {% for n_name,n_data in nodes.items() %} |
28 | 35 | Host {{ n_name }} |
29 | | - HostName {{ public_ip }} |
| 36 | + HostName {{ public_ip or hostname }} |
30 | 37 | RequestTTY yes |
31 | 38 | RemoteCommand {{ netlab_path }} connect -i {{ defaults.multilab.id|default('default') }} {{ n_name }} |
32 | 39 | UserKnownHostsFile /dev/null |
33 | | - StrictHostKeyChecking no |
| 40 | + StrictHostKeyChecking off |
| 41 | + UserKnownHostsFile /dev/null |
34 | 42 | LogLevel QUIET |
35 | 43 |
|
36 | 44 | {% endfor %} |
| 45 | +{% for n_name,n_data in nodes.items() |
| 46 | + if n_data.ansible_connection in ssh_conn %} |
| 47 | +Host {{ n_name }}.ssh |
| 48 | + HostName {{ n_data.ansible_host }} |
| 49 | + User {{ n_data.ansible_user }} |
| 50 | + ProxyJump {{ hostname }} |
| 51 | + StrictHostKeyChecking off |
| 52 | + UserKnownHostsFile /dev/null |
| 53 | + |
| 54 | +{% endfor %} |
0 commit comments