Tech · · 3 min read · Part 3 of 3

Ansible Dev Server using Code Server

A browser-based VS Code environment for Ansible development, reachable from any device

code-server is an open-source project from Coder that runs Visual Studio Code on a remote server and serves it to your browser. Put the Ansible tools on that server, and you have a fully configured Ansible development environment on any device with a browser: a laptop, a borrowed machine, even a tablet.

Why use code-server for Ansible development

  • Work anywhere: open a browser and log in.
  • Consistent environment: every developer works in the same set-up.
  • Minimal local requirements: nothing to install on the device you’re using.
  • Central management: update and secure it in one place.

How it fits together

  1. A remote server (a VM, or an EC2 instance on AWS) runs code-server.
  2. The Ansible Development Tools are installed on that server.
  3. You reach it from a browser, with password authentication, over an encrypted connection.

Diagram: a web browser connects over HTTPS to a server running code-server, which hosts Visual Studio Code and the Ansible command-line tools

Prerequisites

  • A Linux server or cloud instance, such as an AWS EC2 instance or an on-premises VM.
  • SSH access to it.
  • Python 3, for the Ansible tools.
  • Optional: Podman or Docker, if you want to run execution environments.
  • Optional: a domain name, if you want to reach it over HTTPS without an SSH tunnel.

Install code-server

  1. Download and install code-server:

    curl -fsSL https://code-server.dev/install.sh | sh
  2. Set the password. Edit ~/.config/code-server/config.yaml:

    bind-addr: 127.0.0.1:8080
    auth: password
    password: choose-a-long-random-password
    cert: false

    127.0.0.1 is code-server’s default, and the safe one: it listens only on the server itself, and you reach it through a tunnel or a reverse proxy (next section).

  3. Start code-server:

    code-server

    Terminal output of code-server starting: it reports its version, the config file it uses, that authentication is enabled with the password from the config file, and that it is not serving HTTPS

    To keep it running after you log out, run it as a service. The code-server documentation shows the systemd set-up.

  4. Install the Ansible tools in a virtual environment, and the Ansible extension:

    python3 -m venv ~/ansible-venv
    ~/ansible-venv/bin/pip install ansible-dev-tools
    code-server --install-extension redhat.ansible
    code-server --list-extensions

    A virtual environment keeps the tools apart from the system’s Python; recent Ubuntu and Debian releases refuse a system-wide pip install. In code-server, point the Ansible extension’s Python interpreter setting at ~/ansible-venv/bin/python so it finds them.

    code-server installs extensions from Open VSX, not from Microsoft’s VS Code Marketplace, which only allows Microsoft’s own products. Most popular extensions, including Red Hat’s Ansible extension, are published there; a few Microsoft extensions are not.

Reach it from your browser

The simplest secure way: an SSH tunnel. From your laptop:

ssh -N -L 8080:127.0.0.1:8080 user@your-server

Then browse to http://localhost:8080 and log in with the password from the config file. The traffic travels inside SSH, and nothing new is exposed on the server.

The code-server login page in a browser, asking for the password from the config file

From any device, without SSH: HTTPS through a reverse proxy. Point a domain at the server, keep code-server on 127.0.0.1:8080, and put Caddy or NGINX with Let’s Encrypt in front of it. That gives you a real certificate, which code-server needs for some features to work.

Without HTTPS, code-server warns that it is “being accessed in an insecure context”, and web views and the clipboard may not work:

VS Code for the Web running in the browser, with code-server’s warning that it is being accessed in an insecure context

Keep it safe

  • Don’t expose plain HTTP to the internet. If you must bind to 0.0.0.0 for a quick test, restrict the port in your firewall or AWS security group to your own IP address, and undo it afterwards.
  • Use a long random password, and don’t commit config.yaml anywhere.
  • Keep code-server updated. Run the install script again to upgrade.

Wrapping up

code-server gives you a portable, consistent Ansible workspace that follows you to any browser, with the server doing the heavy lifting. Start with the SSH tunnel; add HTTPS when you need to reach it from devices without SSH.

Note I used AI assistance to draft or edit this post, working from my own notes and experience, and I reviewed every change. The opinions and any mistakes are mine.