
Build commander, python-based ansible clone to manage tens or hundreds of linux machines, run commands with tunable speed, authenticate via ssh keys or passwords, and securely transfer files via ssl.
Demonstrate Commander, a multi-host command runner, showing usage, authentication, and running multiple commands in parallel to scale to tens or hundreds of hosts, with secure file copy at the end.
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.
Use virtualenv to create isolated python environments for each project, preventing library version conflicts. Learn why virtualenv is preferred over conda and how to install it in the terminal.
Create a new Python project with an automatic virtual environment and Python 3. Add a file named Commander, print hello, then enable execute permission and run ./commander to confirm.
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.
Create virtual machines on Digital Ocean to test an Ansible clone using Python, spin up five droplets in San Francisco with standard defaults, and copy their IPs for later coding.
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.
Create a regular user named James Bond, grant sudo access by adding him to the admin group for root commands via sudo, then verify root privileges.
Learn to implement sudo functionality in a python-based ansible clone using paramiko by invoking a shell, handling password prompts, and verifying the final who am I output.
Create a real commander script by importing argparse, building an ArgumentParser, adding -c and -t arguments to run commands on multiple hosts, and parse_args and validate input.
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.
Copy each host IP and add the James Bond user to all five hosts, enable the auto add policy for hosts, encrypt the password with OpenSSL, and create home directory.
Generate an RSA key pair, accept the default file location, and copy the public key to digital ocean droplets to enable passwordless, key-based authentication with the commander script.
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 to add the sudo flag to a python-based Ansible clone by enhancing the commander script with pseudo authentication, conditional prompts, and commands that run with zero parameters.
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 command echo support to a Python script for an Ansible clone, introducing an echo flag and an echo_check function to print commands before execution.
Learn to disable keys when using username and password by updating connection strings to turn off the agent and key lookups, preventing key-based authentication conflicts.
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 how Python threading speeds up parallel command execution by running a host shell function per host, eliminating outer loops, and using early returns on failures.
Add a command line threads flag to your Python Ansible clone, using a capital T argument with a store action, optional integer defaulting to one, to avoid overloading cores.
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.
Extend commander with scp-like copy and download capabilities, turning local shell scripts into a lightweight playbook for remote hosts, and install ACP client to enable remote file transfer.
Implement SCP-like functionality by adding copy and download features to Commander, using the ACP client transport, handling local and remote paths, and enabling recursive copy and test workflows.
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.
Extend commander with Runner features and SSA tunneling for firewall or proxy access. Find Commander version on the speaker's Tax Labs blog and contact Jason at Tax Labs dot com.
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.