arista-eosplus / packer-ztpserver

Packer.io set up of ZTP server
18 stars 9 forks source link

Automatically Create a Full-Featured ZTPServer

Introduction

This project uses Packer to automatically create a full-featured ZTPServer VM. By using this method, you can be sure that all of the required packages and dependencies are installed right out of the gate. This setup will include some extra services like XMPP, Syslog, NTP, DHCP, DNS, LLDPAD and others to help you get a complete testing environment running quickly.

You can also use Packer to automate the setup of vEOS nodes.

What's Supported

Getting Started

There is a nice, shiny python script that will make your life very easy!

Here's what it's going to do:

Requirements

Go Time

Script Arguments

arista:packer-ztpserver arista$ ./create-ztpserver.py -h
usage: create-ztpserver.py [-h] -H {vmware,esxi,virtualbox} -o
                           {fedora,ubuntu,eos} [-n VMNAME] [-d DISK_SIZE]
                           [-u ESXI_USER] [-e ESXI_HOST] [-p DATASTORE_PATH]
                           [-i ESXI_NETWORK]

Automatically install the ZTPServer Demo

optional arguments:
  -h, --help            show this help message and exit
  -H {vmware,esxi,virtualbox}, --hypervisor {vmware,esxi,virtualbox}
                        Hypervisor to create VM in
  -o {fedora,ubuntu,eos}, --os {fedora,ubuntu,eos}
                        Desired OS to use for VM
  -n VMNAME, --vmname VMNAME
                        The Virtual Machine name
  -d DISK_SIZE, --disk-size DISK_SIZE
                        VM Disk size in MB
  -u ESXI_USER, --esxi-user ESXI_USER
                        The ESXi username
  -e ESXI_HOST, --esxi-host ESXI_HOST
                        The IP or hostname of the ESXi host
  -p DATASTORE_PATH, --datastore-path DATASTORE_PATH
                        The ESXi path to save the VM
  -i ESXI_NETWORK, --esxi-network ESXI_NETWORK
                        vSphere network assigned to VM that allows
                        communication with local builder
  1. Retrieve the ZTPServer Packer files here or run from a shell on your local machine.

    git clone https://github.com/arista-eosplus/packer-ztpserver.git
    cd packer-ztpserver
    
  2. Fire in the hole

    NIX-based Terminal

    python ./create-ztpserver.py -H [vmware|virtualbox|esxi] -o [fedora|ubuntu|eos] --vmname VMNAME-PREFIX
    

    IMPORTANT: You will have to enter your sudo password so keep an eye on it.

    Windows-based Command-Prompt

    IMPORTANT: Open the command prompt as an Administrator so you don't have to authorize every command

    C:\> C:\Python27\python.exe ./create-ztpserver.py -H [vmware|virtualbox|esxi] -o  [fedora|ubuntu|eos] --vmname VMNAME-PREFIX
    

    Note: Your Python executable might be somewhere else, or part of your %PATH% in which case you could just type python, but this is just meant to be a general idea.

    Examples:

    Create an Ubuntu ZTPServer VM for Fusion with VM name prefix "my-demo"

    create-ztpserver.py -H vmware -o ubuntu --vmname my-demo
    

    Create a Fedora ZTPServer VM for Workstation with VM name prefix "my-demo"

    create-ztpserver.py -H vmware -o fedora --vmname my-demo
    

    Create a Fedora ZTPServer VM for Fusion with 10GB disk

    create-ztpserver.py -H vmware -o fedora -d 10000
    

    Create a ZTPServer VM that runs on an EOS device

    create-ztpserver.py -H vmware -o eos
    

    Create a Fedora ZTPServer VM that runs on an ESXi host

    create-ztpserver.py -H esxi -o fedora -u esxiUser -e esxi-host.example.com -p Datastore1/ztpservers -i net_vlan100
    
  3. When the script exits successfully you will have a full-featured ZTPServer. We've gone ahead and placed some demo files from GitHub to make life a little easier. All of the interesting files are in /usr/share/ztpserver and /etc/ztpserver/.

  4. Log into the server with user ztpsadmin and password eosplus. Simply type the following to start the standalone ztpserver:

    ztps
    

    or to send all console output to a file:

    ztps --debug </dev/null >~/ztps-console.log 2>&1 &

    You can stop the ztps process anytime by typing

    pkill ztps
    

    You can also run the ZTPServer as an Apache Web Server Gateway Interface. All of the necessary config is already in place. Just start Apache:

    Note: The ZTPServer can only run in Standalone mode OR as an WSGI App. Kill the ztps process first if you would like to run the WSGI App.

    systemctl start httpd
    systemctl enable httpd
    

    WSGI related logs will be in /var/log/messages and /var/log/httpd/error.log Refer to the ZTPServer Documentation to learn how to customize your ZTPServer. You can create some vEOS nodes using Packer to help get your demo working even faster.

Post-Installation Tips

Set the PATH Variable

If Packer is installed via the script above, the packer binary path wasn't permanently added to your system PATH variable. If you intend on using Packer again, you might consider updating your PATH variable.

NIX-Based Terminal

echo "export PATH=$PATH:~/packer-bin" >> ~/.bash_profile

and then restart your bash.

Windows-Based Command Prompt

setx PATH "%PATH%;%USERPROFILE%\packer-bin"

and then restart your cmd.exe.

Upload the EOS VM to an Arista Switch

Step 1: First SCP the resulting .vmdk file to your Arista switch

scp disk.vmdk admin@eos-switch-1:/mnt/dst/path

Step 2: Create Virtual-Machine entry. Log into your EOS switch:

eos-switch-1#conf
eos-switch-1(config)#virtual-machine ztps
eos-switch-1(config-ztps)#disk-image usb1:/path/disk.vmdk image-format vmdk
eos-switch-1(config-ztps)#memory-size 1024 ! Choose a desired size
eos-switch-1(config-ztps)#enable

Step 3: Confirm the VM is running

eos-switch-1#show virtual-machine
VM Name              Enabled    State
-------              -------    -----
ztps                 Yes        Running

Step 4: Console into the ZTPServer VM

eos-switch-1#bash
[admin@eos-switch-1 ~]$ sudo virsh
virsh # list
Id Name                 State
----------------------------------
1 ztps                  running

virsh # console 1
error: Failed to get local hostname
error: Failed to get connection hostname
Connected to domain ztps
Escape character is ^]

[root@ztps ~]# echo hello world

The Minor Details

How the ESXi Builder Works

Packer provides built-in support for VM creation on VMware ESXi. In this case, you still execute the create-ztpserver script on your local machine, but you provide details for Packer to upload and create the VM on your ESXi host.

Require Parameters

Virtual Networks

Host-only virtual networks will be created:

The ZTPServer VM

If you run into any snags, please feel free to raise an issue and attach the logs.