Working with SSH

This recipe centers on using the SSH plugin. With this plugin, you are able to connect to appliances (think managed routers, switches, and so on...) or a Linux- or Solaris-based system, run programs, or transfer files.

Getting ready

We need to be able to create a new workflow. We also need a Linux or Solaris system that we can access via SSH (for example, as root). If you don't have a Linux system handy, you can use the Orchestrator appliance itself.

For the SCP example, you need to allow Orchestrator access to its local filesystem, or use the default /var/run/vco directory. Refer to the Configuring access to the local filesystem recipe in Chapter 2, Optimizing Orchestrator Configuration.

If you want to connect to the appliance itself (127.0.0.1) you need to enable SSH access as shown in the Tuning the appliance recipe in Chapter 2, Optimizing Orchestrator Configuration.

How to do it...

We split this recipe into three parts: SSH access, SSL key access, and SCP usage.

Using SSH

You will find a very good, while rather chatty (logs), SSH workflow in Library | SSH | Run SSH command. However, we will create a new short version to showcase SSH:

  1. Create a new workflow and create the following variables:

    Name

    Type

    Place

    Usage

    Host

    String

    IN

    The IP or FQDN of the host we want to connect to.

    User

    String

    IN

    The username to connect to the host.

    Password

    SecureString

    IN

    The password of the user to connect to the host.

    Command

    String

    IN

    The command we want to run on the host.

    Output

    String

    OUT

    The result of the command we run.

    exitcode

    Number

    OUT

    The exit code 0 = OK.

    Error

    String

    OUT

    The error message encountered.

  2. Add a scriptable task to the schema and enter the following script:
          // Open a new SSH session with password 
          var mySSHSession = new SSHSession(host , user); 
          mySSHSession.connectWithPassword(password); 
          //execute the SSH command 
          mySSHSession.executeCommand(command , true); 
          // prepare output 
          output=mySSHSession.output; 
          exitcode=mySSHSession.exitCode; 
          error=mySSHSession.error; 
          //disconnect the SSH session 
          mySSHSession.disconnect(); 
    
  3. Save and close the workflow.

When running this workflow, you will have to supply a command string. The string can be a single command or a string of commands the Linux system can utilize. A command you can try is date.

Using SSL key authentication

In the previous example, we used password authentication to log in to the Linux host system. We can use SSL keys to allow automatic login without using a password, which is the method commonly used for automation purposes.

To enable SSL authentication, first we need an SSL key, and we need to store it on the target Linux system. We will use the existing workflows to accomplish this:

  1. Start the workflow by navigating to Library | SSH | Generate key pair.

    Tip

    Every time you run this command, a new SSL key pair with the vco_key and vro_key.pub is generated in the /etc/vco/app-server/ directory.

  2. Use the default setting and don't enter a password. Basically, just click on Submit.
  3. Next, we need to register the SSL key on the host with the user we will use for the connection. To do this, we will use the existing workflow by navigating to Library | SSH | Register vCO public key on host. This workflow will add vco-key.pub onto the file /root/.ssh/authorized_keys.
  4. Start the workflow, enter the hostname of the target server as well as the credentials of the user, and click on Submit.
  5. The SSL pairing is now done. Let's try it out. Create a duplicate (or change the original) of the workflow you have created in the first section of this recipe.
  6. Replace the mySSHSession.connectWithPassword(Password); line with mySSHSession.connectWithIdentity("../conf/vco_key" , "");. The shorter path works as Orchestrator's working directory is the app-server directory.
  7. Remove the password in-parameter from the workflow.
  8. Run the workflow. You won't need a password any longer.

Using SCP

SCP stands for Secure CoPy and allows you to transfer files using an SSH encryption tunnel. However, before we can copy anything from or to the Orchestrator server, we need to have a directory that Orchestrator has access to (see the Configuring access to the local filesystem recipe in Chapter 2, Optimizing Orchestrator Configuration. You can also use the default directory, /var/run/vco.

  1. Make a copy of one of the SSH workflows: either the password or the SSL one.
  2. Remove the command in-parameter and add the following in-parameter:

    Name

    Type

    Place

    Usage

    filename

    String

    IN

    The name of the file.

    localDir

    String

    IN

    The directory on the Orchestrator server.

    remoteDir

    String

    IN

    The directory on the remote host.

  3. Replace the mySSHSession.executeCommand(Command , true); line with one of the following, depending on whether you want to send or receive a file:

    Upload

    mySSHSession.putFile(localDir+file , remoteDir);

    Download

    mySSHSession.getFile(remoteDir+file , localDir);

  4. Save and run the workflow.

How it works...

Using SSH together with Orchestrator generates a very powerful team. You can use SSH to access an existing Linux system, configure it, or to connect to a Linux-based management system, such as a Red Hat satellite server.

But, even more powerfully, you can connect to the Orchestrator appliance itself. If you generate a SSL key and register it on 127.0.0.1 (Orchestrator itself), you can run commands as root, such as mounting a NFS or SMB directory. Please be aware that opening SSH for Orchestrator may be considered a security risk.

SCP can be used in conjunction with Orchestrator resources to upload and download files or to transfer any other files between Orchestrator and a target system. Please note that you can also transfer files from one remote system to another using Orchestrator as a temporary storage between transfers.

See also

  • Refer to the Configuring access to the local filesystem recipe in Chapter 2, Optimizing Orchestrator Configuration.
  • Refer to the File operations recipe in this chapter.

The example workflows are:

  • 09.04.1 SSH (short with password)
  • 09.04.2 SSH (short with SSL Key)
  • 09.04.3 SCPput
  • 09.04.4 SCPget
  • 02.01 Tuning the Appliance
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset