Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Latest commit

 

History

History
270 lines (203 loc) · 8.36 KB

avd-vscode-docker.md

File metadata and controls

270 lines (203 loc) · 8.36 KB

How to use AVD image with VSCODE

About

This how-to explains how to leverage avdteam/base image as shell under VScode to get a consistent developement and testing environment regardless operating system running Ansible. This how-to is applicable to any OS where VScode can be installed.

Table of content

Configure AVD environment

Before running all code with a container, we have to download current AVD ecosystem with the following command:

  • On Linux or Macos:
$ curl -fsSL https://get.avd.sh | sh
  • On Windows:
PS C:\Users\User> Invoke-WebRequest -OutFile install.sh -Uri \
https://raw.githubusercontent.com/arista-netdevops-community/avd-install/master/install.sh

PS C:\Users\User> bash install.sh

This script git clone AVD and CVP collection as well as example repository to get started with example.

$ cd ansible-arista

$ ls -al
total 24
-rw-rw-r--  1 tom tom 2517 Jul 20 09:09 Makefile
drwxrwxr-x  8 tom tom 4096 Jul 20 09:09 ansible-avd
drwxrwxr-x  8 tom tom 4096 Jul 20 09:09 ansible-avd-cloudvision-demo
drwxrwxr-x  9 tom tom 4096 Jul 20 09:09 ansible-cvp

Devcontainer with docker image

Requirements

For windows user, WSL should be configured on your system

Configure devcontainer

VScode provides a function to open a workspace in either remote ssh server, in a WSL instance (for windows only) or in a container. In this how-to, we will leverage this functionality with avdteam/base

$ pwd
/home/tom/arista-ansible

# create VScode folder
$ mkdir .devcontainer

# edit configuration
$ vim .devcontainer/devcontainer.json

Copy following content to devcontainer.json:

{
    "name": "AVD development",
    "image": "avdteam/base:3.6",

    "settings": {
        "terminal.integrated.shell.linux": "/bin/zsh",
        "python.linting.enabled": true,
        "python.linting.pylintEnabled": true,
        "python.linting.flake8Path": "/root/.local/bin/flake8",
        "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
        "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
        "python.linting.pylintPath": "/root/.local/bin/pylint",
        "python.testing.pytestPath": "/root/.local/bin/pytest"
    },

    "extensions": [
         "ms-python.python",
         "vscoss.vscode-ansible",
         "timonwong.ansible-autocomplete",
         "codezombiech.gitignore",
         "tuxtina.json2yaml",
         "jebbs.markdown-extended",
         "donjayamanne.python-extension-pack",
         "njpwerner.autodocstring",
         "quicktype.quicktype",
         "jack89ita.copy-filename",
         "mhutchie.git-graph",
         "eamodio.gitlens",
         "yzhang.markdown-all-in-one",
         "davidanson.vscode-markdownlint",
         "christian-kohler.path-intellisense",
         "ms-python.vscode-pylance",
         "tht13.python"
    ],
    "containerEnv": {
        "ANSIBLE_CONFIG": "./ansible.cfg"
    }
}

Open content in container

After you configured .devcontainer/devcontainer.json correctly, you can open VScode and start local container with following actions:

VScode will do the following configuration:

  • Download avdteam/base
  • Install extensions in new container
  • Configure paths for python tools
  • Configure path for ansible.cfg (to fix issue with windows and mount point)

Once container is running, you can continue to edit your files in VScode and your shell will be executed inside a container.

Agent pid 186
➜  arista-ansible pwd
/workspaces/arista-ansible

➜  arista-ansible

When using devcontainer feature, git information is shared from host and allow user to run git commands with all correct information.

Devcontainer with docker image

Requirements

For windows user, WSL should be configured on your system

Configure devcontainer

VScode provides a function to open a workspace in either remote ssh server, in a WSL instance (for windows only) or in a container. In this how-to, we will leverage this functionality with avdteam/base

  • On Linux or Macos:
$ pwd
/home/tom/arista-ansible

# create VScode folder
$ mkdir .devcontainer

# edit configuration
$ vim .devcontainer/devcontainer.json

Copy following content to devcontainer.json:

{
  "name": "Docker from Docker Compose",
  "dockerComposeFile": "docker-compose.yml",
  "service": "ansible",
  "workspaceFolder": "/projects",

  "settings": {
    "terminal.integrated.shell.linux": "/bin/zsh"
	},

  "extensions": [
         "ms-python.python",
         "vscoss.vscode-ansible",
         "timonwong.ansible-autocomplete",
         "codezombiech.gitignore",
         "tuxtina.json2yaml",
         "jebbs.markdown-extended",
         "donjayamanne.python-extension-pack",
         "njpwerner.autodocstring",
         "quicktype.quicktype",
         "jack89ita.copy-filename",
         "mhutchie.git-graph",
         "eamodio.gitlens",
         "yzhang.markdown-all-in-one",
         "davidanson.vscode-markdownlint",
         "christian-kohler.path-intellisense",
         "ms-python.vscode-pylance",
         "tht13.python"
   ],
   "containerEnv": {
	    "ANSIBLE_CONFIG": "./ansible.cfg"
   }
}

Then create docker-compose.yml file under .devcontainer/ folder with following content to run an ansible instance and 2 mkdocs to expose documentation for ansible-cvp and ansible-avd:

version: "3"
services:
  ansible:
    image: avdteam/base:3.6
    volumes:
      - ../:/projects
    command: [ "/bin/sh", "-c", "while true; do sleep 30; done;" ]

  webdoc_cvp:
    image: titom73/mkdocs:latest
    volumes:
      - ../ansible-cvp:/docs
    ports:
      - 8001:8000
    entrypoint: ""
    command: ["sh", "-c", "pip install -r ansible_collections/arista/cvp/docs/requirements.txt && mkdocs serve --dev-addr=0.0.0.0:8000 -f mkdocs.yml"]

  webdoc_avd:
    image: titom73/mkdocs:latest
    volumes:
      - ../ansible-avd:/docs
    ports:
      - 8000:8000
    entrypoint: ""
    command: ["sh", "-c", "pip install -r ansible_collections/arista/avd/docs/requirements.txt && mkdocs serve --dev-addr=0.0.0.0:8000 -f mkdocs.yml"]

Open content in container

After you configured .devcontainer/devcontainer.json correctly, you can open VScode and start local container with following actions:

VScode will do the following configuration:

  • Download avdteam/base
  • Install extensions in new container
  • Configure paths for python tools
  • Configure path for ansible.cfg (to fix issue with windows and mount point)

Once container is running, you can continue to edit your files in VScode and your shell will be executed inside a container.

Agent pid 186
➜  arista-ansible pwd
/workspaces/arista-ansible

➜  arista-ansible

For other containers, you can access to documentation using your browser and following URLs: