Create and bootstrap a multi-host track
This guide explains how to create and bootstrap a track with multiple hosts.
You can give a learner access to multiple hosts within a single trackβ€”such as a Docker container host and a Kubernetes virtual machine host for scenarios where your software is cluster-based or you need load balancing.

Track set up scripts execution order

The point of interest in a multi-host track is the track setup script execution, as each host has its own setup script. And the Instruqt platform runs the track setup scripts sequentially in order of alphanumerically sorted hostnames. If you want to run setup scripts parallel on all hosts, see the Bootstrap a multi-host track section for orchestrating the setup from the track setup script on the first host and use Secure Shell (SSH) to run a script on another host.
Now let's see how you create a multi-host track.

Create a multi-host track

The easiest way to create a multi-host track is to start with a single host track and add one or more hosts to that track. Here you will start with a debian container and then add a g1-small virtual machine.

Step 1: Create a track with a single host

🌐 Web UI
πŸ’» Instruqt CLI
  1. 1.
    Open your browser and go to play.instruqt.com. ↳ Instruqt shows your content.
  2. 2.
    Click Create track on the Content page. ↳ The Start creating content page opens.
  3. 3.
    Click Create from template to open the Instruqt templates page.
  4. 4.
    Select the Sandbox container template. ↳ The Track info pop-up opens.
  5. 5.
    In the Track title field, enter your title.
  6. 6.
    In the Track slug field, modify the slug if you want to.
  7. 7.
    Click Create. ↳ Instruqt creates the single host track and shows the Track overview page.
  1. 1.
    Type the following command to create a track:
    instruqt track create
  2. 2.
    Enter the track title:
    ==> Track title: TRACK_TITLE
  3. 3.
    Enter option 2 to select From a template:
    ==> Start with an empty track or use a template:
    ​
    [1] From scratch
    For full flexibility, start with an empty track
    [2] From a template
    To get started quickly, start from one of our templates
    ​
    Please select your method: 2
  4. 4.
    Enter the number of the template you want to use:
    ==> Choose a template:
    ​
    [1] AWS Cloud Account
    Learn how to build tracks with an AWS account
    [2] Sandbox container
    Get started quickly with just one container-based sandbox host.
    [3] Sandbox virtual machine
    Use a virtual machine (VM) as a sandbox host
    [4] Helm chart
    Learn how to install helm charts with Instruqt.
    [5] Kubernetes
    Learn how to build Kubernetes-based tracks with this template
    [6] Multi-node Kubernetes cluster
    Setup a Kubernetes cluster on multiple sandbox hosts
    [7] VSCode & TypeScript
    Edit and test TypeScript applications in VSCode
    ​
    Please select your template: 2
    ↳ Instruqt CLI creates the single host track.

Step 2: Add a host

Now add a g1-small virtual machine as the second host.
🌐 Web UI
πŸ’» Instruqt CLI
Continuing from the Track overview page.
  1. 1.
    Click Edit track details, followed by Sandbox.
  2. 2.
    Click Add Virtual Machine + to add another host.
  3. 3.
    In the Name field, enter your name for this virtual machineβ€”for example, avirtualmachine.
  4. 4.
    In the Image field, enter centos-7.
  5. 5.
    In the Machine type list, select g1-small.
  6. 6.
    In the Shell field, enter /bin/bash as the shell for your container.
  7. 7.
    Click Save, followed by Back to return to the Track overview page.
  8. 8.
    Click Edit on the challenge, followed by Tabs.
  9. 9.
    Click New tab to add a tab for the added host.
  10. 10.
    In the Title field, enter your title for this tab.
  11. 11.
    In the Type list, select Terminal.
  12. 12.
    In the Host list, select the name of the host you added.
  13. 13.
    Click Save, followed by Back to return to the Track overview page.
  14. 14.
    Click Start track to play your multi-host track.
  15. 15.
    Click Start when your environment is created. ↳ You have two tabs now, each for a different host, as you can see by their prompts.
  1. 1.
    Move over to your code editor and open the config.yml file.
  2. 2.
    Add this section to the containers property:
    virtualmachines:
    - name: avirtualmachine
    image: centos-7
    shell: /bin/bash
    machine_type: g1-small
  3. 3.
    Save the file and now open the assignment.md file from the challenge directory.
  4. 4.
    Add this section to the tabs property:
    - title: YOUR_SHELL_NAME
    type: terminal
    hostname: YOUR_HOST_NAME
  5. 5.
    Save the file and move back to Instruqt CLI.
  6. 6.
    Deploy your multi-host track to the Instruqt platform:
    instruqt track push
  7. 7.
    Open your browser and go to play.instruqt.com. ↳ Instruqt now shows the created track in your content.
  8. 8.
    Click your multi-host track, followed by Start track.
  9. 9.
    Click Start when your environment is created. ↳ You have two tabs now, each for a different host, as you can see by their prompts.

Bootstrap a multi-host track

Instruqt sorts the hosts in a track in alphanumeric order and executes the track setup scripts sequentially. So in the track you have made so far, the virtual machine configuration script is executed first because the name, avirtualmachine, comes before the name container .
To run track setup scripts parallel on both hosts, you have to create a track setup for the virtual machine that runs a script on the container through SSH:
🌐 Web UI
πŸ’» Instruqt CLI
Continuing from the Track overview page.
  1. 1.
    Click Edit track details, followed by Sandbox.
  2. 2.
    Click Lifecycle scripts.
  3. 3.
    Click setup under container. ↳ An editor window for the track setup script opens.
  4. 4.
    Add the following code into the editor window to enable the container to run SSH scripts:
    #!/bin/bash
    ​
    cat <<EOF >> "$HOME/.ssh/config"
    Host *
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
    EOF
    ​
    apt-get update && apt-get install -y openssh-client ncat vim
    ​
    cat >> $HOME/.bashrc <<EOF
    export FOO=bar
    export BAZ=qux
    EOF
  5. 5.
    Click Save.
  6. 6.
    Click setup under avirtualmachine. ↳ An editor window for the track setup script opens.
  7. 7.
    Add the following code into the editor window:
    #!/bin/bash
    ​
    yum install -y nmap-ncat
    ​
    cat <<EOF >> "$HOME/.ssh/config"
    Host *
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
    EOF
    ​
    while ! ssh container true; do
    echo "Waiting for container SSH to be available"
    sleep 1
    done
    ​
    ssh container "echo 'hello from the avirtualmachine track setup' >> /root/from-vm.txt"
    ↳ This code enables SSH, and in line 16, it runs the echo command on the other host container through SSH.
  8. 8.
    Click Save, followed by Close and Back.
  9. 9.
    Click Build track βš™οΈ.
  10. 10.
    Click Start track, followed by Start when Instruqt has created your environment. ↳ Your track play shows two terminals, one for the container and one for the virtual machine. The terminal for the container should be active. If not, click the container tab to activate the container terminal.
  11. 11.
    Enter the ls command to show the directory content. ↳ The file from-vm.txt is listed. The virtual machine track setup script created this file in the container. This shows that the virtual machine track setup has run the echo command on the container.
  1. 1.
    Head over to Instruqt CLI and enter the following command to create the track_script directory:
    md track_scripts
  2. 2.
    Move over to your code editor and open a new file. This file will contain the track setup script for the container host.
  3. 3.
    Add the following code into the container track setup script file to enable the container to run SSH scripts:
    #!/bin/bash
    ​
    cat <<EOF >> "$HOME/.ssh/config"
    Host *
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
    EOF
    ​
    apt-get update && apt-get install -y openssh-client ncat vim
    ​
    cat >> $HOME/.bashrc <<EOF
    export FOO=bar
    export BAZ=qux
    EOF
  4. 4.
    Save the file as setup-container in the track_scripts directory.
  5. 5.
    Open another new file. This file will contain the track setup script for the virtual machine host.
  6. 6.
    Add the following code into the virtual machine track setup script file:
    #!/bin/bash
    ​
    yum install -y nmap-ncat
    ​
    cat <<EOF >> "$HOME/.ssh/config"
    Host *
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
    EOF
    ​
    while ! ssh container true; do
    echo "Waiting for container SSH to be available"
    sleep 1
    done
    ​
    ssh container "echo 'hello from the avirtualmachine track setup' >> /root/from-vm.txt"
    ↳ This code enables SSH, and in line 16, it runs the echo command on the other host container through SSH.
  7. 7.
    Save the file as setup-avirtualmachine in the track_scripts directory.
  8. 8.
    Move back to Instruqt CLI and deploy your multi-host track to the Instruqt platform:
  9. 9.
    instruqt track push
  10. 10.
    Open your browser and go to play.instruqt.com. ↳ Instruqt now shows the created track in your content.
  11. 11.
    Click your multi-host track, followed by Start track.
  12. 12.
    Click Start when Instruqt has created your environment. ↳ Your track play shows two terminals, one for the container and one for the virtual machine. The terminal for the container should be active. If not, click the container tab to activate the container terminal.
  13. 13.
    Enter the ls command to show the directory content. ↳ The file from-vm.txt is listed. The virtual machine track setup script created this file in the container. This shows that the virtual machine track setup has run the echo command on the container.
Nice! You have tracks on a string.
Copy link
Edit on GitHub
Outline
Track set up scripts execution order
Create a multi-host track
Step 1: Create a track with a single host
Step 2: Add a host
Bootstrap a multi-host track