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:
- A remote server (VM or EC2) running Code Server.
- Ansible Development Tools installed in the server environment.
- Browser Access with authentication and HTTPS for security (for this demo, we will not use HTTPS)
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
-
Download and install Code Server
curl -fsSL https://code-server.dev/install.sh | sh
-
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
-
Configure password authentication, edit ~/.config/code-server/config.yaml
bind-addr: 0.0.0.0:8080 auth: password password: your-secure-password
-
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
-
Access in Browser, visit http://your-server-ip:8080
Login using the password previously set in the config file.
Visual Studio Code Workspace from Remote Code Server
-
Install ansible-navigator
sudo apt install python3-pip pip install ansible-navigator --user echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.profile source ~/.profile
-
Install podman and git
sudo apt install podman sudo apt install git podman --version git --version
-
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
-
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
-
Clone sample playbook and test run
git clone https://github.com/enzobercasio/ansible-demo.git
Recommendations
- Use HTTPS in production
- Use strong authentication
- Restrict access to trusted IPs when possible
- Keep your Code Server instance updated
- Automate Ansible Dev Server with Ansible
- Refer to official VS Code - Code Server documentation for licensing and other FAQs.
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.