
Install Python to follow this course. On Mac, install Homebrew, run brew install python, and verify Python is at least 3.9.12.
Use the PyCharm IDE as the primary coding environment for this course. Choose to work with Visual Studio Code, Atom, or Sublime Text if you prefer.
Install paramiko in a virtual environment using the command line or PyCharm, activate the venv, run pip install paramiko, and verify by importing and instantiating the client.
Connect to a digital ocean vm via ssh for a single host, verify known_hosts, and run who am I as root, illustrating stdout timing and a sleep fix.
Learn to securely pass credentials by using Python's OS module to read username and password from environment variables, validate them, and authenticate hosts.
Learn to connect to multiple hosts with a Python script using Paramiko. Handle comma separated targets, prepare environment variables, and capture command output for execution results.
Add key-based authentication to commander with a dash k optional key file and a default rsa key path, enforcing a username for key use and fallback to password.
Learn how to implement sudo authentication in a Python-based Ansible clone by opening a shell channel, sending sudo commands, handling password prompts, and validating root access.
Learn to execute multiple commands with sudo by updating the script to split a command string, run each command per host, format outputs, and add echo for clarity.
Add a try block around connection logic to catch exceptions, print failures, and continue to the next host, with a 5-second timeout to prevent hanging and graceful authentication failure messages.
Learn to build an Ansible clone using Python by implementing threading, a worker function, a queue, and a main guard, then test with a command-line run.
Demonstrates a final demo of multi-threaded host execution across 20+ Digital Ocean hosts, using commander to run three commands in parallel, showing faster performance with more threads and simple authentication.
Add safety checks to prevent unintended copy or download while executing commands, requiring a colon in copy arguments to avoid not enough values to unpack error and block dash C.
Learn to build an Ansible like command line utility called Commander
Commander is a replica of scripts I built while working at companies like PayPal, eBay, and Symantec to help manage & patch thousands of Linux systems and network devices.
In this course you'll learn how to
- Build a command line utility in Python
- Use Python to SSH to Linux machines and run commands.
- Setup sudo for running commands as root
- Use Threading to increase speed by reducing wait time on network i/o
- Upload & Download files to servers via SCP in Python
- And more...
Pre-requisites
Access to machines running SSH OR the ability to sign up for Digital Ocean or another cloud provider (AWS,GCP, etc) to create machines to test with.
Python installed on your machine.
Who is this course for
This course is perfect for DevOps/SRE/Cloud engineers who are looking to automate the boring stuff in their day to day lives using Python & SSH.
If you're using Ansible or Rundeck today, you can use Commander as a foundation to extend and build exactly what you need for your use-cases.
Additionally, this course will be fun for Python beginners who want to work on a useful project that teaches you how to build a command line utility and implement Threading in Python.
This course is intended to be short, sweet and straight to the point.
I look forward to hearing your feedback & seeing what you build with this knowledge.