On-demand GNS3-Server automation using Packet
GNS3 was extensively developed in the past years. It is good that the Client and Server functions are decoupled, so we can use the GUI but still run the simulation on cloud resources. For this kind of virtualization bare metal service required as GNS3 using KVM/QEMU, and most cloud providers are not supporting Nested virtualization.
Packet provides on-demand physical server resources, so it is a good target to run ESXi or GNS3 server in the cloud.
The main idea is to book the required resource only for the time of the simulation. Persistency still required so that the GNS3 images and project data is available for future use.
Deployment of the solution is controlled via an Ansible playbook. For this to work we need the following tasks:
- Add an SSH key to Packet
- Create the Server at Packet
- Attache storage to the server using S3FS
- Verify the server is reachable via SSH
- Connect to the server and download GNS3-server installation script
- Run this script
- update DDNS entry
- Connect and mount the Block storage
- restart GNS3 service
- configure some basic security
We would also require another playbook to destroy the server:
- Unmount /opt and disconnect the storage
- Destroy the server
Now let’s see what is required on the client side.
Ansible, Packet-Python and the requirements:
Installing the automation framework (Ansible) on the client machine is straightforward. Documentation also available how to use Ansible with Packet.com. Generally what we require is two packages:
- Ansible
- Packet-Python
I would suggest to use pip for the installation. I am using Miniconda3 on my Mac, and that comes now with a default Python3.7 environment.
Packet.com - registration and setup
Unlike AWS or Google Cloud (which provide only Virtual Machines), Packet gives you full access to a true dedicated server, but with the same automation and flexibility you expect from a public cloud. Since you have direct access to the virtualization instructions on the CPU, running GNS3 on Packet is a great experience.
Registration at packet.com is easy and automatic like in case of any cloud provider. There is a special bonus for GNS3 users as described here.
In short, what to do:
- Register, setup the details, enable the GNS3 promo code, add payment method.
- Enable 2FA authentication
- Create a project, create an API key, write down the project id. This project ID you can find on the Project Settings page.
With these steps completed we are ready to leverage the packet.com API.
Duckdns - registration and setup
This is a nice free DDNS solution. DDNS is required so that the server can be reference in GNS3 with a single hostname.
- Just go to www.duckdns.org
- Login using one of the method
- Write down the sub domain and Token
Storage - Wasabi - registration and setup
In our solution persistence is still required. We could use Packet’s block storage, but the availability of the service is region dependent. Wasabi seems to fit, and it is cost effective, can be used for other proposes as well. It is fast also. Just head to http://wasabi.com, register.
- Create a new Object Storage bucket (write down the name). Use the proper region.
- Create an Access Key, and write down the Key and Secret.
Creating the Ansible environment.
In a dedicated directory I have created the following files:
hosts
: File includes variables and ansible definitions, statics.packet-playbook.yml
: Ansible Playbook file to create and deploy the serverpacket-delete-playbook.yml
: to destroy the server already running..newhost
: Temporal file that will contain the information about the device we have provisioned.passwd-s3fs.j2
: Template for password file.
The hosts file
Don’t forget to fill in the missing information from Packet, Duckdns, Wasabi. Also reference the Pub and Priv SSH keys.
Playbook to provision the server
Playbook to decommission the server
To start the playbook navigate to the directory and issue:
ansible-playbook -i hosts packet-playbook.yml