# Devcontainers for ansible collection development

**URL:** <https://forum.ansible.com/t/devcontainers-for-ansible-collection-development/3774>\
**Category:** Get Help\
**Tags:** devtools, netscaler, collections\
**Created:** [February 9, 2024, 7:38am UTC](https://forum.ansible.com/t/devcontainers-for-ansible-collection-development/3774 "2024-02-09T07:38:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumanth-lingappa](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sumanth-lingappa/32/839_2.png) [@sumanth-lingappa](https://forum.ansible.com/u/sumanth-lingappa)\
**Post date:** [February 9, 2024, 7:38am UTC](https://forum.ansible.com/t/devcontainers-for-ansible-collection-development/3774/1 "2024-02-09T07:38:14Z")

</div>

I am the maintainer of `netscaler.adc` ansible collection. I am thinking to add a devcontainer support for the collection.

Any heads up on the devcontainer with respect to ansible collection development please?

---

<div class="post-metadata">

**Author:** ![atul\_mohan](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@atul\_mohan](https://forum.ansible.com/u/atul_mohan)\
**Post date:** [January 5, 2025, 5:01pm UTC](https://forum.ansible.com/t/devcontainers-for-ansible-collection-development/3774/2 "2025-01-05T17:01:46Z")

</div>

Directory Structure:  
Ensure your collection has the following structure:  
ansible\_collections/  
└── netscaler  
└── adc  
├── meta  
├── plugins  
│ ├── inventory  
│ ├── modules  
│ └── module\_utils  
├── roles  
├── tests  
├── .devcontainer  
│ ├── devcontainer.json  
│ └── Dockerfile  
└── galaxy.yml  
Create .devcontainer Directory:  
Inside your collection’s root directory, create a .devcontainer folder.  
Dockerfile:  
Here’s a Dockerfile example specifically for Ansible development:

```auto
# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Set the working directory in the container to /home/vscode
WORKDIR /home/vscode

# Install system dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    git \
    ssh \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# Install Ansible and related tools
RUN pip install --no-cache-dir \
    ansible \
    ansible-lint \
    molecule \
    docker \
    molecule[docker] \
    testinfra

# Install netscaler.adc collection
RUN ansible-galaxy collection install netscaler.adc -p /usr/share/ansible/collections

# Set up non-root user for VSCode
RUN groupadd --gid 1000 vscode \
    && useradd --uid 1000 --gid 1000 -m vscode \
    && mkdir -p /home/vscode/.vscode-server/extensions \
    && chown -R vscode:vscode /home/vscode

# Make sure the non-root user has the rights to use sudo without password
RUN echo "vscode ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# Switch to non-root user
USER vscode

# Set environment variables for non-root user
ENV PATH="/home/vscode/.local/bin:${PATH}"

# Default command when container starts
CMD ["/bin/bash"]

```

devcontainer.json:  
Here’s a devcontainer.json to configure the development environment:

```auto
{
    "name": "Ansible Collection Development for netscaler.adc",
    "build": {
        "dockerfile": "Dockerfile"
    },
    "settings": {
        "terminal.integrated.defaultProfile.linux": "bash",
        "python.linting.enabled": true,
        "python.linting.pylintEnabled": true,
        "python.formatting.provider": "black",
        "python.formatting.blackArgs": [
            "--line-length=120"
        ],
        "editor.formatOnSave": true,
        "ansible.python.interpreter": "/usr/local/bin/python"
    },
    "extensions": [
        "ms-python.python",
        "vscoss.vscode-ansible",
        "redhat.ansible",
        "ms-vscode-remote.remote-containers",
        "esbenp.prettier-vscode"
    ],
    "forwardPorts": [],
    "postCreateCommand": "ansible-galaxy collection install --force -p /usr/share/ansible/collections netscaler.adc",
    "remoteUser": "vscode"
}

```
