How To Install speedtest-cli on Ubuntu / CentOS / Debian using Ansible

(: August 16, 2019)

Introduction

The proliferation of internet connectivity has come with numerous opportunities that were only far dreams more than two decades ago. As more people get into the web, speed of access to web resources whether videos, web content or e-books has become something of such importance that no one can afford to ignore.

People all over the globe loathe slow speeds especially when they are following their favorite TV series or downloading their favorite content online. Due to this, thanks to the opensource community, tools have been developed to check the kind of speeds that exist between your computer and the resources you are eager to consume.

One of the tools that you will easily find out there is speedtest. We are sure you have heard of the speedtest website where you get to measure the speed of your internet connectivity. It is a wonderful tool until you are in a server without GUI or a browser and you still need to check your speed connectivity. This guide fills that gap because it shows how to install and use speedtest-cli. As the name suggests, it is a command-line version of speedtest and you can easily install and use it in your minimal/core Linux server.

.td_uid_2_5d909d3479783_rand.td-a-rec-img{text-align:left}.td_uid_2_5d909d3479783_rand.td-a-rec-img img{margin:0 auto 0 0}

This guide shows how to install speedtest-cli using Ansible on Ubuntu 18.04 and CentOS 7 and how you can use it to test your connectivity speeds.

We assume you have installed Ansible environment, python and python-setuptools (for Ubuntu) and are all working well. The installation script depends on python-setuptools for Ubuntu.

Step one: Edit your inventory file

You can use your default /etc/ansible/hosts file or you can create a new one as well as long as you specify it while running your playbook

$ sudo vim /etc/ansible/hosts

# Add your server IPs
[worker1]
172.21.98.186

Step Two: Create your Playbook as shown below

---
- hosts:  worker1 
  become: true
  tasks:
    - name: Check if Python is installed
      raw: test -e /usr/bin/python
      changed_when: false
      failed_when: false
      register: check_python

    - name: Install Python and setuptools
      raw: test -e /usr/bin/apt && (apt -y update && apt install -y python-setuptools  && apt install -y python) || (yum -y install python libselinux-python)
      when: check_python.rc != 0

    - name: Auto-Create project directory to dump speedtest-cli files from git
      file: path=/tmp/test state=directory

    - name: Get speedtest-cli from git
      git: repo=https://github.com/sivel/speedtest-cli.git dest=/tmp/test/

    - name: Change to speedtest-cli directory and install it
      become: yes
      command: chdir=/tmp/test/ python setup.py install 

Once the Playbook has run successfully, it is time to use speedtest-cli. Let us get on it.

The simplest speedtest using speedtest-cli is by simply running it on your terminal as:

$ speedtest-cli
Retrieving speedtest.net configuration… 

The above will measure upload and download speeds in reference to the closest server that it will find.

In case you would wish to measure your speed against a server of your choice, then you must know its id. To get the id of the server, please run the following

$ speedtest-cli --list

This will generate a very long list of servers. However, you can, of course, grep the results using your City name for example:

$ speedtest-cli --list | grep New York                                                                                                                            13098) Pilot (New York, NY, United States) [11842.04 km]
16976) Spectrum (New York, NY, United States) [11842.04 km]
5029) AT&T (New York, NY, United States) [11842.04 km]
10390) Speedtest.net (New York, NY, United States) [11842.04 km]
663) Optimum Online (New York, NY, United States) [11842.04 km]
18381) AT&T Wireless (New York, NY, United States) [11842.04 km]
16888) Natural Wireless (New York, NY, US) [11842.04 km]
7170) ISPnet, Inc (New York, NY, United States) [11842.04 km]
10546) Sprint (New York, NY, United States) [11842.04 km]
16686) CCleaner (New York, NY, United States) [11842.04 km]
21016) Starry, Inc. (New York, NY, United States) [11842.04 km]
21313) Data Room (New York, NY, United States) [11842.04 km]
6030) fdcservers.net (New York, NY, United States) [11842.04 km]
18956) Hivelocity Hosting (New York, NY, United States) [11842.04 km]
20326) Honest.net (New York, NY, United States) [11842.04 km]
24374) GTT.net (New York, NY, United States) [11842.04 km]
22715) Newforce Solutions (New York, NY, United States) [11842.04 km]
25070) Stealth Communications (New York, NY, United States) [11842.04 km]
26314) Castcrown Limited (New York, NY, United States) [11842.04 km]
18098) Atlantic Metro (New York, NY, United States) [11842.04 km]
25168) MinhaLista (New York, NY, United States) [11842.04 km]

After you have the list, you can now choose the one you would like to use then run

$ speedtest-cli --server 13098    # for Pilot (New York, NY, United States) server.
Retrieving speedtest.net configuration…

If you would prefer to use bytes per second instead of bits per second by default, just use the –bytes option and you are good to go.

$ speedtest-cli --bytes --server 6030
Retrieving speedtest.net configuration…

There are a few more options that you may find interesting for your use. More information can be found at:

Speedtest Github Page

Conclusion

Now you have a working speedtest-cli and we hope it will help you in your use-case. Thank you for visiting and reading through. Check below for other guides you might be interested in:

Top RHCSA / RHCE Certification Study Books

Best Books To learn Docker and Ansible Automation

Ceph vs GlusterFS vs MooseFS vs HDFS vs DRBD

Install Zulip Chat Server on Ubuntu / Debian

.td_uid_4_5d909d3479976_rand.td-a-rec-img{text-align:left}.td_uid_4_5d909d3479976_rand.td-a-rec-img img{margin:0 auto 0 0}

Related posts

HowTo Debian/Ubuntu Linux Auto Mount Windows NTFS File System [ntfs-3g]

SXI ADMIN

No, Satoshi Nakamoto Hasn’t Moved a Thing

SXI ADMIN

US Government to Submit ‘Oversized’ Argument in ICO Fraud Case

SXI ADMIN

How Bitcoin Tech Could Make Infamous Anonymous Tor Network More Powerful

SXI ADMIN

Blockchain Startup Symbiont Adds Ex-Morgan Stanley Director

SXI ADMIN

Importing Databases and Tables with phpMyAdmin

SXI ADMIN

OpenBazaar Raises $5 Million from Bitmain, OMERS Ventures

SXI ADMIN

Redhat / CentOS / Fedora Linux Install XCache for PHP 5

SXI ADMIN

South Korean Banks Face Scrutiny Over Crypto Exchange Ties

SXI ADMIN

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More