mirror of
https://github.com/duncs/clusterssh.git
synced 2025-04-21 09:09:06 +00:00
add support for .ssh/config include directive
This commit is contained in:
parent
a3e8e221e7
commit
f9c6120477
1 changed files with 32 additions and 18 deletions
|
@ -37,30 +37,44 @@ sub new {
|
|||
|
||||
# load in ssh hostname for later use
|
||||
if ( !%ssh_hostname_for || !$ssh_configs_read{ $self->{ssh_config} } ) {
|
||||
$ssh_configs_read{ $self->{ssh_config} } = 1;
|
||||
if ( open( my $ssh_config_fh, '<', $self->{ssh_config} ) ) {
|
||||
while ( my $line = <$ssh_config_fh> ) {
|
||||
chomp $line;
|
||||
next unless ( $line =~ m/^\s*host\s+(.*)/i );
|
||||
read_ssh_file($self, $self->{ssh_config});
|
||||
|
||||
# account for multiple declarations of hosts
|
||||
$ssh_hostname_for{$_} = 1 foreach ( split( /\s+/, $1 ) );
|
||||
}
|
||||
close($ssh_config_fh);
|
||||
|
||||
$self->debug( 5, 'Have the following ssh hostnames' );
|
||||
$self->debug( 5, ' "', $_, '"' )
|
||||
foreach ( sort keys %ssh_hostname_for );
|
||||
}
|
||||
else {
|
||||
$self->debug( 3, 'Unable to read ',
|
||||
$self->{ssh_config}, ': ', $!, $/ );
|
||||
}
|
||||
$self->debug( 5, 'Have the following ssh hostnames' );
|
||||
$self->debug( 5, ' "', $_, '"' ) foreach ( sort keys %ssh_hostname_for );
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub read_ssh_file($$) {
|
||||
my ( $self ) = shift;
|
||||
my ( $filename ) = glob(shift);
|
||||
$self->debug(3, 'Reading SSH file: ', $filename);
|
||||
|
||||
$ssh_configs_read{ $filename } = 1;
|
||||
|
||||
if ( open( my $ssh_config_fh, '<', $filename ) ) {
|
||||
while ( my $line = <$ssh_config_fh> ) {
|
||||
chomp $line;
|
||||
|
||||
if ( $line =~ /^\s*include\s+(.+)/i ) {
|
||||
$self->read_ssh_file($1);
|
||||
next;
|
||||
}
|
||||
|
||||
next unless ( $line =~ m/^\s*host\s+(.*)/i );
|
||||
|
||||
# account for multiple declarations of hosts
|
||||
$ssh_hostname_for{$_} = 1 foreach ( split( /\s+/, $1 ) );
|
||||
}
|
||||
close($ssh_config_fh);
|
||||
}
|
||||
else {
|
||||
$self->debug( 3, 'Unable to read ',
|
||||
$filename, ': ', $!, $/ );
|
||||
}
|
||||
}
|
||||
|
||||
sub get_hostname {
|
||||
my ($self) = @_;
|
||||
return $self->{hostname};
|
||||
|
|
Loading…
Add table
Reference in a new issue