thanos1983 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I have created a script that can run in parallel multiple ssh connections, I am using the Net::OpenSSH::Parallel module for my task. Well my problem now is that I do not know if there is a way to apply multiple ssh connections to different primary servers, and as a second step I need to apply ssh connections to secondary servers and execute a set of commands.

Update: Primary and secondary servers are first and second line of servers. Further analysis, I have a set of different servers that I need to ssh simultaneously, those are the primary servers. Once I login to the primary servers then as a second step I want to ssh to the secondary servers.

localhost --> Primary 1st --> Secondary 1st localhost --> Primary 2nd --> Secondary 2nd localhost --> Primary 3rd --> Secondary 3rd ... ... ... localhost --> Primary nth --> Secondary nth

So my question, is that possible to be done with Perl?

Update 2: I have found a possible solution, ssh tunnel via multiple hops but I was wondering if it can be done by a module or possibly to be combined with Net::OpenSSH::Parallel module.

It is mandatory and important to me to execute the commands simultaneously at all servers. this is the reason that I am using the Net::OpenSSH::Parallel module.

Once more thank you for your time and effort to assist me.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re: How to apply multiple parallel consecutive ssh sessions
by salva (Canon) on Jan 06, 2015 at 23:43 UTC
    What are "primary" and "secondary" servers?

    Elaborate your problem description, please!

      Hello salva,

      Thank you for your time and effort reading my question, I have updated the question and I have added a small graph to explain the steps of my process.

      Seeking for Perl wisdom...on the process of learning...not there...yet!
        You can use Net::OpenSSH::Gateway.

        It never went into CPAN because I was unhappy with its internal architecture and was planning a complete revamp, but unfortunately never got the time/guts to actually do it.

        In any case, it works reliably. Just install it and tell Net::OpenSSH(::Parallel) to use it with the gateway option:

        $pssh->add_host($secondary_server, gateway => { proxies => "ssh://$primary_server" }, ... );
        Or in case you want to pass additional options when constructing the underlaying Net::OpenSSH object used to connect to the primary server:
        $pssh->add_host($secondary_server, gateway => { proxies => { url => "ssh://$primary_serve +r", user => $primary_user, password => $primary_passwor +d, ... } }, ... );
Re: How to apply multiple parallel consecutive ssh sessions
by jellisii2 (Hermit) on Jan 07, 2015 at 12:45 UTC
    This sounds like something that would be better accomplished by a tool like Salt, Puppet, or something of its ilk?

      Hello jellisii2,

      Thank you for your time and effort. Both tools seems to be interesting but because I have all ready developed my solution in Perl and I do not want to recreate something from scratch.

      It always good to know that there are alternatives to get things done.

      Seeking for Perl wisdom...on the process of learning...not there...yet!