Skip to content

Commit bdde10a

Browse files
committed
Generate ssh_config file with a netlab report
The 'ssh_config' report generates a configuration file that can be included in client ~/.ssh/config file to access netlab devices straight through a client SSH session using RemoteCommand on netlab server to connect to the devices.
1 parent 05583bc commit bdde10a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

netsim/reports/ssh_config.j2

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{% set ssh_defaults = defaults.ssh|default({}) %}
2+
{% set hostname = ssh_defaults.hostname|default('netlab') %}
3+
{% set public_ip = ssh_defaults.publicip|default('127.0.0.1') %}
4+
{% set netlab_path = ssh_defaults.netlabpath|default('netlab') %}
5+
#
6+
# This SSH configuration file allows you to connect to netlab devices running
7+
# on a remote server straight from your workstation
8+
#
9+
# Save it into the ~/.ssh directory (or similar) and include it in your ~/.ssh/config
10+
# file with the "Include" directive (which has to be before the first Host directive)
11+
#
12+
# You can change the SSH parameters with these environment variables
13+
#
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
16+
# NETLAB_SSH_NETLABPATH The path to 'netlab' command (if it's not in PATH)
17+
#
18+
Host {{ hostname }}
19+
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 #}
26+
27+
{% for n_name,n_data in nodes.items() %}
28+
Host {{ n_name }}
29+
HostName {{ public_ip }}
30+
RequestTTY yes
31+
RemoteCommand {{ netlab_path }} connect -i {{ defaults.multilab.id|default('default') }} {{ n_name }}
32+
UserKnownHostsFile /dev/null
33+
StrictHostKeyChecking no
34+
LogLevel QUIET
35+
36+
{% endfor %}

0 commit comments

Comments
 (0)