ArchiTechTales

From Blueprints to Breakthroughs

Ansible Dev Server Using Code Server

Why use Code Server for Ansible Development

Code Server is an open-source project that lets you run Visual Studio Code on a remote server and access it via a web browser. This means you can have a fully configured Ansible development environment available anywhere, on any device.

Key Benefits

  • Work Anywhere: Just open a browser and login.
  • Consistent Environment: Every developer works in the same set up.
  • Minimal Local Requirements: No local installation, only access via browser.
  • Centralized Management: Easy to update and secure in one place.

Architecture Overview

The setup involves:

  1. A remote server (VM or EC2) running Code Server.
  2. Ansible Development Tools installed in the server environment.
  3. Browser Access with authentication and HTTPS for security (for this demo, we will not use HTTPS)

Ansible Development Server

Prerequisites

  • A linux-based server or cloud instance (e.g. AWS EC2 or on-prem VM)
  • Docker or Podman installed (optional but recommended for containerized development)
  • Required port for Code Server access is accessible (e.g add 8080 in Security Group for AWS EC2)
  • Domain name (optional) for secure HTTPS access

Install Code Server in Server

  1. Download and install Code Server

    curl -fsSL https://code-server.dev/install.sh | sh
    
  2. Start Code Server

    To run in background

    sudo systemctl enable --now code-server@ubuntu
    

    Or if you don’t want a background service to run

    code-server
    

    Ansible Development Server

  3. Configure password authentication, edit ~/.config/code-server/config.yaml

    bind-addr: 0.0.0.0:8080
    auth: password
    password: your-secure-password
    
  4. Restart Code Server

    To run in background

    sudo systemctl daemon-reload
    sudo systemctl restart code-server@ubuntu
    

    Or if you don’t want a background service to run

    code-server
    

    Ansible Development Server

  5. Access in Browser, visit http://your-server-ip:8080

    Login using the password previously set in the config file. Ansible Development Server

    Visual Studio Code Workspace from Remote Code Server Ansible Development Server

  6. Install ansible-navigator

    sudo apt install python3-pip
    pip install ansible-navigator --user
    echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.profile
    source ~/.profile
    
  7. Install podman and git

    sudo apt install podman
    sudo apt install git
    podman --version
    git --version
    
  8. Deploy base ansible settings

    In VS Code, go to Settings, type in @ext:redhat.ansible

    • You can enable Execution Environment
    • Change the container engine (Docker or Podman), for our case we will use podman
    • Add the Execution Environment Image

    Ansible Development Server

  9. Add ansible extension

    code-server --install-extension redhat.ansible
    

    To see the list of installed extensions

    code-server --list-extensions
    

    To find the code to use for other extensions, refer to VS Code Marketplace

  10. Clone sample playbook and test run

    git clone https://github.com/enzobercasio/ansible-demo.git
    

    Ansible Development Server

Recommendations

Additional settings

For Podman additional user

sudo vi /etc/subuid
sudo vi /etc/subgid 
sudo podman system migrate

Code Server is a powerful option for Ansible playbook development, giving you flexibility, consistency, and portability. Whether you run it on a VM, in the cloud, it helps you focus on writing automation without worrying about local machine setup.