Skip to content

Ansible, GCP & AWS Developer's Starter Kit for VS Code Remote - Containers extension

License

Notifications You must be signed in to change notification settings

hiranp/vscode-devcontainer-ansible

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Dockerfile to provide an isolated Ansible environment for interactive use in the command-line, Visual Studio Code's devcontainer feature, or in a CI/CD pipeline.

Image based off of ansible toolset, which bundles Ansible Community Toolset bundle for developing and testing tools in a single container.

Added support for Visual Studio Code Remote - Containers extension, so you can develop directly inside the docker image.

Finally, direct support for AWS and GCloud cli.

What is bundled inside the container

Generally the containers should bundle the latest stable versions of the tools below. An exact list can be seen in requirements.txt file used for building the container.

VSCode Support

VScode Devcontainer

   "extensions": [
        "ms-python.python",
        "tht13.python",
        "zbr.vscode-ansible",
        "vscoss.vscode-ansible",
        "redhat.vscode-yaml",
        "oderwat.indent-rainbow",
        "yzhang.markdown-all-in-one",
        "donjayamanne.githistory",
        "eamodio.gitlens",
        "waderyan.gitblame"
    ]

Ansible Collection

The following Ansible collections are installed. You can edit requirement.yml to change it.

Docker Pulls GitHub Actions

Installation

Automated builds are available on Docker Hub.

docker pull hiranp/ansible-toolset

But you can also build your own if you want.

docker build -t hiranp/ansible github.com/hiranp/ansible-toolset
#Local Build
$ docker build -t hiranp/ansible-toolset .devcontainer/

Quick Start

Interactive

Running from the command-line as below allows for ad-hoc commands, and mounts the current directory for interactive usage and testing of playbooks

docker run -it --rm -v "${PWD}:/workspace" -w=/workspace --entrypoint=/bin/bash hiranp/ansible-toolset

Run playbook:

docker run -v "${PWD}":/workspace:ro -v ~/.ansible/roles:/root/.ansible/roles -v ~/.ssh:/root/.ssh:ro --rm hiranp/ansible-toolset ansible-playbook playbook.yml

Another options is to create aliases:

alias ansible='docker run -v "${PWD}":/workspace:ro --rm hiranp/ansible-toolset'
alias ansible-playbook='docker run -v "${PWD}":/workspace:ro -v ~/.ansible/roles:/root/.ansible/roles -v ~/.ssh:/root/.ssh:ro --rm hiranp/ansible-toolset ansible-playbook'
alias ansible-vault='docker run -v "${PWD}":/workspace:ro --rm hiranp/ansible-toolset ansible-vault'

NOTE: For direct Git access to local git repo

docker run -e GIT_DISCOVERY_ACROSS_FILESYSTEM=1 -v "${PWD}":/workspace:ro --rm hiranp/ansible-toolset

Visual Studio Code devcontainer

  1. Install and configure the Visual Studio Code Remote - Containers extension
  2. Copy devcontainer.json to .vscode\devcontainer.json or .devcontainer.json
  3. Update and customise as required

CI/CD

Below is a basic example for use with gitlab-ci but this should be transferable to other providers.

# .gitlab-ci.yml

---
image: hiranp/ansible-toolset

stages:
  - test
  - deploy

lint:
  stage: test
  script:
    - ansible-lint .

deploy:
  stage: deploy
  script:
    - ansible-playbook playbook.yml
...

About

Ansible, GCP & AWS Developer's Starter Kit for VS Code Remote - Containers extension

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published