Workstation Setup
I will be editing files using VSCode on my Windows desktop, connected via the Remote-SSH extension. This gives me the full IDE experience (syntax highlighting, linting, file explorer, integrated terminal) while keeping all files on the control node where Ansible actually runs.
01 SSH Key - Windows
First, I setup SSH key authentication from my Windows pc to ansible-ctrl.
I generated a key pair with PowerShell.
ssh-keygen -t ed25519 -C "Windows-desktop > ansible-ctrl" -f $env:USERPROFILE\.ssh\ansible-ctrlI left the passphrase empty for convenience since this is on my personal pc.
I then copied the public key to ansible-ctrl
type $env:USERPROFILE\.ssh\ansible-ctrl.pub | ssh nesto@ansible-ctrl "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"- Line 1:
- Reads the public key and pipes it over SSH to append it to the
authorized_keysfile onansible-ctrl
Then I tested the key.
ssh -i $env:USERPROFILE\.ssh\ansible-ctrl nesto@ansible-ctrlIt should connect without prompting for a password.
01a Windows SSH Config
Next, I updated the SSH config file on my Windows pc so that VSCode and the command line know how to connect to lab hosts without specifying the full details every time.
Host ansible-ctrl
HostName ansible-ctrl
User user
IdentityFile ~/.ssh/ansible-ctrl
Host clab
HostName clab
User user
IdentityFile ~/.ssh/ansible-ctrl
Host gitea
HostName gitea
User user
IdentityFile ~/.ssh/ansible-ctrl
Host netbox
HostName netbox
User user
IdentityFile ~/.ssh/ansible-ctrlNow I should be able to connect without a password.
02 VSCode Setup
I then installed the Remote-SSH Extension. This extension connects VSCode to a remote machine over SSH, installs a lightweight server component on the remote, and then all file operations, terminal sessions, and extensions run on the remote machine. The Windows VSCode instance is just a frontend.
From within VSCode:
- Press Ctrl+Shift+X to open the Extensions panel
- Search for “Remote - SSH”
- Install the extension by Microsoft
Next, I connected to ansible-ctrl VM.
- Press Ctrl+Shift+P to open the Command Palette
- Type “Remote-SSH: Connect to Host”
- Select ansible-ctrl from the list
- A new VCCode window opens, connected to the remote machine
- When prompted for the platform select Linux
Once connected I opened the project directory.
- Press Ctrl+Shift+P
- Type “File: Open Folder”
- Navigate to /home/nesto/network-automation-lab
- Click Ok
Every file I open, edit, and save is on ansible-ctrl.
02a Extensions
containerlab/configs/ directory and backup files more readable.02b Settings
I configured a few settings to make the editing experience a bit easier. These settings are store in a .vscode/settings.json file in the project directory and apply only when the project is open.
| |
- Line 8:
- Points the Ansible extension to my project’s virtual environment Python interpreter. This ensures the extension can find Ansible, ansible-lint, and the other installed collections for autocompletion and validation.
- Lines 13-17:
- File associations tell VSCode which language mode to use for each file type.
- Lines 20-22:
- Forces 2-space indentation with spaces (never tabs).
detectIndentation: falseprevents VSCode from guessing and overriding this setting based on existing file content. - Lines 26-27:
- These match the
trailing-whitespaceandend-of-file-fixerprecommit hooks. - Lines 30-34:
- Hides directories that shouldn’t appear in the file explorer.
The Ansible extension’s linting feature depends on ansible-lint being installed in the Python environment.
| |
The Ansible extension should now automatically start showing linting warnings and errors inline as I type.
02c Integrated Terminal
The integrated terminal in VSCode opens a shell on ansible-ctrl when connected via Remote-SSH.
Because I setup ~/.bashrc to auto-activate the virtual environment, the terminal should show the (.venv) prompt immediately. If it doesn’t it’s because the ~/bashrc file isn’t being sourced.
To fix it, I add the activation code to .bash_profile as well, or set the terminal profile in VSCode settings:
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash",
"args": ["--login"]
}
}03 Other Tools
MobaXterm
I use this to quickly SSH into a VM if I don’t have VSCode running.
WinSCP
I use this to quickly transfer files from my Windows PC to any VM.
04 Workflow
- Open VSCode
- Connect to
ansible-ctrl - Create a feature branch: `git checkout -b feat/name-of-change
- Edit playbooks, roles, etc.
- Run playbooks from the terminal
- Review changes in the Source Control panel (Ctrl+Shift+G)
- Stage, commit, push from terminal
- Open Gitea, create a PR, review, merge