MVP monorepo to rapidly develop scalable, reliable, high-quality components for Amazon Linux instance configuration management

Overview

Ansible Amazon Base Repository

About

Ansible Amazon Base Repository is an MVP monorepo to rapidly develop scalable, reliable, high-quality components for Amazon Linux instance configuration management.

Setting Up Ansible Environment

Configuring Python VENV and Ansible

Note: This document assumes that you are working on Mac

  1. Create a new virtual environment with pyenv

    $ pyenv virtualenv miniconda3-latest ansible
    
  2. Activate your new python virtual environment

    $ pyenv activate ansible
    
  3. Install poetry

    $ conda install poetry
    
  4. Install dependencies

    $ poetry install
    
  5. Check ansible

    $ ansible --version
    

Editor Configuration

Code editors are major software development productivity tools. VSCode is a game changer.

VSCode should be configured for typical Python development with the following extensions:

VSCode should be configured to associate most of the files in the repository with Ansible. Check that your ansible files are have Ansible set in the "Select Language Mode". In VSCode the difference between YAML and Ansible Language Mode is night and day. Example .vscode/settings.json

{
  "files.associations": {
    "kitchen*": "yaml",
    "*.yml": "ansible"
  },
}

Python should be setup with the following:

    "editor.renderWhitespace": "all",
    "editor.rulers": [
        80,
        100,
        120
    ],
    "[python]": {
        "editor.tabSize": 4,
        "editor.insertSpaces": true,
        "editor.formatOnSave": true
    },
    "[yaml]": {
        "editor.insertSpaces": true,
        "editor.tabSize": 2,
        "editor.autoIndent": "none",
        "editor.quickSuggestions": {
            "other": true,
            "comments": false,
            "strings": true
        },
        "editor.formatOnPaste": true
    },
    "python.linting.enabled": true,
    "python.linting.pylintEnabled": true,
    "python.linting.banditEnabled": true,
    "python.linting.banditArgs": [
        "-x",
        "./tests",
        "-r",
    ],
    "python.linting.pylintArgs": [
        "--disable=C0301,C0111,E0402,W0702,W0108,W0703"
    ],
    "python.linting.pycodestyleEnabled": true,
    "python.linting.pycodestyleArgs": [
        "--ignore E501"
    ],
    "python.formatting.provider": "black",
    "python.languageServer": "Pylance",
    "python.envFile": "/Users/current.user/.vspyenv",
    "python.testing.pytestArgs": [
        "-s",
        "-vvvv"
    ],
    "pythonTestExplorer.testFramework": "pytest",
    "markdownlint.config": {
        "MD013": {
            "line_length": 120,
            "tables": false,
            "code_blocks": false
        },
        "MD025": false,
        "MD033": false,
        "MD036": false,
        "MD041": false
    },
    "testExplorer.hideEmptyLog": false,

Setting Up VirtualBox Environment

Access to local VMs running Amazon Linux helps rapidly and safely iterate on Ansible code.

Install VirtualBox and Vagrant

VirtualBox can be installed with Homebrew. However, every once in a while the latest build of VirtualBox has a broken functionality. At the time of writing, VirtualBox 6.1.28 has a broken Host Network Manager. Good build of VirtualBox is 6.1.26. Install Virtual Box from the link.

Vagrant is a HashiCorp Ruby project to provide VirtualBox abstraction. Use Homebrew to install vagrant

$ brew install vagrant

Configuring Test Kitchen

Test Kitchen is a Ruby project to automate Infrastructure as Code development life-cyle.

Install RVM

$ gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

$ \curl -sSL https://get.rvm.io | bash -s stable --ruby

Add RVM to your profile

# Add RVM
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

Install test-kitchen gems

$ gem install test-kitchen kitchen-ansible kitchen-ec2

Downloading Amazon Linux v2 Vagrant Box

Amazon Linux v2 is a feature-rich Linux distribution maintained by Amazon. Amazon page about Amazon Linux Images lists various formats available, including Amazon Linux v2 virtualbox.

Download Amazon Linux v2 vagrant box from HashiCorp Vagrant Cloud.

Import vagrant box:

$ vagrant box add amazon2 <downloaded box>
$ vagrant box list

Build an Optimized Amazon Linux 2 Vagrant Box

Default Amazon Linux 2 vagrant box does not come with Ansible installed. Any time we run kitchen with the default Amazon Linux 2 box, kitchen will spend time installing Ansible. In order to save development time, we will build a box that includes Ansible and Docker.

Run kitchen converge with kitchen.box.yml

$ KITCHEN_YAML=kitchen.box.yml kitchen converge box

List running VirtualBox VMs and make note of the full name of the kitchen-ansible-amazon-base-box-amazon VM

$ VBoxManage list vms
"kitchen-ansible-amazon-base-box-amazon-cb9dedd7-fd27-4344-b026-bd3a2b7a340e" {9cf5ed90-d3a0-4e95-b742-6c9249c0cf34}

Run vagrant to export kitchen-ansible-amazon-base-box-amazon

$ vagrant package --base kitchen-ansible-amazon-base-box-amazon-cb9dedd7-fd27-4344-b026-bd3a2b7a340e
==> kitchen-ansible-amazon-base-box-amazon-cb9dedd7-fd27-4344-b026-bd3a2b7a340e: Attempting graceful shutdown of VM...
==> kitchen-ansible-amazon-base-box-amazon-cb9dedd7-fd27-4344-b026-bd3a2b7a340e: Clearing any previously set forwarded ports...
==> kitchen-ansible-amazon-base-box-amazon-cb9dedd7-fd27-4344-b026-bd3a2b7a340e: Exporting VM...
==> kitchen-ansible-amazon-base-box-amazon-cb9dedd7-fd27-4344-b026-bd3a2b7a340e: Compressing package to: /Users/current.user/work/ansible-amazon-base/package.box

Import package.box as amazon2-ansible

$ vagrant box add amazon2-ansible package.box
$ vagrant box list
amazon2         (virtualbox, 0)
amazon2-ansible (virtualbox, 0)

Remove kitchen instance

KITCHEN_YAML=kitchen.box.yml kitchen destroy box

Remove package.box from the local folder

Environment Variable Overwrites for Kitchen

Kitchen will use amazon2-ansible box by default. If you are using a different box, you can set KITCHEN_ANSIBLE_BOX environment variable.

Running Test Kitchen

Change directory to playbooks and run

$ kitchen list

To create a VirtualBox VM and apply an Ansible playbook run

$ kitchen converge docker

To destroy a created VM run

$ kitchen destroy docker

To connect to a VM run

$ kitchen ssh docker

Running Integration Tests

Integration tests are written in TestInfra. To run tests

$ kitchen verify docker

Running Ansible Playbooks on AWS Instances

In order to run Ansible Playbooks on AWS instances, first configure ANSIBLE_ROLES_PATH to point to the roles directory of the repository, e.g.

$ export ANSIBLE_ROLES_PATH=/Users/current.user/work/ansible-amazon-base/role

Also configure ~/.ansible.cfg to format Ansible output as a more readable YAML

[defaults]
stdout_callback = yaml

Choose a playbook and run Ansible

$ ansible-playbook -v -u ec2-user --private-key ~/.ssh/<instance>.pem -i <instance_ip>, playbooks/gst/gst_jupyter.yml

Example Project: Build a Local Docker/Containerd Server VM

Why bother with Docker Desktop when you can build your own Containerd Server?

Check "Host Network Manager" in the File menu of your VirtualBox. Add an interface and make note of the subnet.

Edit kitchen.yml cedocker suit and set private_network to a static IP of your choice.

  - name: cedocker
    provisioner:
      name: ansible_playbook
      playbook: ./playbooks/docker/docker.yml
    driver:
      vm_hostname: cedocker.local
      network:
        - ['private_network', {ip: '192.168.98.121'}]

Run kitchen converge

$ kitchen converge cedocker
...
       PLAY RECAP *********************************************************************
       localhost                  : ok=5    changed=1    unreachable=0    failed=0    skipped=2    rescued=0    ignored=0

       Downloading files from <cedocker-amazon>
       Finished converging <cedocker-amazon> (0m5.54s).
-----> Test Kitchen is finished. (1m15.18s)

SSH into your Containerd VM. Change vagrant's user password from 'vagrant' to something secure. Add your SSH key to ~/.ssh/authorized_keys. Change permissions on /var/run/docker.sock.

$ ssh [email protected]
[email protected]'s password:
Last login: Mon Nov 15 05:47:31 2021 from 10.0.2.2

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/

This system is built by the Bento project by Chef Software
More information can be found at https://github.com/chef/bento

[[email protected] ~]$ passwd
Changing password for user vagrant.
Changing password for vagrant.
(current) UNIX password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[[email protected] ~]$ vi ~/.ssh/authorized_keys
[[email protected] ~]$ sudo chmod a+rw /var/run/docker.sock
exit
logout
Connection to 192.168.98.121 closed.

Create a new Docker context:

$ docker context create cedocker --docker "host=ssh://[email protected]"
cedocker
Successfully created context "cedocker"
$ docker context use cedocker
$ docker context ls
NAME         DESCRIPTION                               DOCKER ENDPOINT                KUBERNETES ENDPOINT   ORCHESTRATOR
cedocker *                                             ssh://[email protected]
default      Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                          swarm

Start using your new Containerd server:

$ docker version
Client: Docker Engine - Community
 Version:           20.10.10
 API version:       1.41
 Go version:        go1.17.2
 Git commit:        b485636f4b
 Built:             Fri Oct 15 14:45:13 2021
 OS/Arch:           darwin/amd64
 Context:           cedocker
 Experimental:      true

Server:
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.15.14
  Git commit:       b0f5bc3
  Built:            Tue Sep 28 19:56:28 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.6
  GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc:
  Version:          1.0.0
  GitCommit:        84113eef6fc27af1b01b3181f31bbaf708715301
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Ansible References

You might also like...
💻  A fully functional local AWS cloud stack. Develop and test your cloud & Serverless apps offline!
💻 A fully functional local AWS cloud stack. Develop and test your cloud & Serverless apps offline!

LocalStack - A fully functional local AWS cloud stack LocalStack provides an easy-to-use test/mocking framework for developing Cloud applications. Cur

The official Magenta Voice Skill SDK used to develop skills for the Magenta Voice Assistant using Voice Platform!

Magenta Voice Skill SDK Development • Support • Contribute • Contributors • Licensing Magenta Voice Skill SDK for Python is a package that assists in

MONAI Deploy App SDK offers a framework and associated tools to design, develop and verify AI-driven applications in the healthcare imaging domain.
MONAI Deploy App SDK offers a framework and associated tools to design, develop and verify AI-driven applications in the healthcare imaging domain.

MONAI Deploy App SDK offers a framework and associated tools to design, develop and verify AI-driven applications in the healthcare imaging domain.

Develop and deploy applications with the Ionburst Cloud Python SDK.

Ionburst SDK for Python The Ionburst SDK for Python enables developers to easily integrate with Ionburst Cloud, building in ultra-secure and private o

toldium is a modular, fast, reliable and customizable multiplatform bot library for your communities
toldium is a modular, fast, reliable and customizable multiplatform bot library for your communities

toldium The easy multiplatform bot toldium is a modular, fast, reliable and customizable multiplatform bot library for your communities, from a commun

ChairBot is designed to be reliable, easy to use, and lightweight for every user, and easliy to code add-ons for ChairBot.

ChairBot is designed to be reliable, easy to use, and lightweight for every user, and easliy to code add-ons for ChairBot. Ready to see whats possible with ChairBot?

unofficial library for discord components(on development)

discord.py-buttons unofficial library for discord buttons(on development) Install pip install --upgrade discord_buttons Example from discord import Cl

An unofficial library for discord components (under-development)
An unofficial library for discord components (under-development)

discord-components An unofficial library for discord components (under-development) Welcome! Discord components are cool, but discord.py will support

A simple Python wrapper for the Amazon.com Product Advertising API ⛺

Amazon Simple Product API A simple Python wrapper for the Amazon.com Product Advertising API. Features An object oriented interface to Amazon products

Comments
  • Amazon Linux v2 box updates

    Amazon Linux v2 box updates

    • Updating notes with information about the latest Amazon Linux v2 images
    • Recurse unnecessary
    • Adding logic to configure Ansible with Python3
    • Add test-kitchen nginx target
    opened by aia 0
Releases(0.1.0)
Owner
Artem Veremey
Artem Veremey
Advanced Number Validator Using telnyx api

Number Validator Python v1.0.0 Number Validator Using telnyx api DISCLAIMER This Tool is only for educational purposes You'll be responsible yourself

xBlackxCoder 3 Sep 24, 2022
:snake: Python SDK to query Scaleway APIs.

Scaleway SDK Python SDK to query Scaleway's APIs. Stable release: Development: Installation The package is available on pip. To install it in a virtua

Scaleway 114 Dec 11, 2022
Opencontactbook - Bulk-manage large numbers of vCard contacts with built-in geolocation

Open Contact Book Open Contact Book is a buiness-oriented, cross-platform, Pytho

Aurélien PIERRE 2 Aug 08, 2022
Mazda Connected Service API wrapper based on pymazda and Flask.

Mazda Connected Service Relay Mazda Connected Service API wrapper based on pymazda and Flask. Usage Make POST calls to https://mymazda.herokuapp.com/{

Alan Chen 10 Jan 05, 2023
Auto-Approved-Bot - Auto Approved Invaite Link Request Telegram Bot

🤖 𝗔𝘂𝘁𝗼-𝗔𝗽𝗽𝗿𝗼𝘃𝗲-𝗕𝗼𝘁 🤖 ℹ️ 𝗨𝘀𝗲𝗴𝗲 ℹ️ When a join request invita

Muhammed 32 Dec 18, 2022
Grade Notifyer Bot

A bot that automatically crawl the submission platform of montefiore to notify the student when a project has been graded.

Julien Gustin 2 Jun 02, 2022
Telegram bot with various Sticker Tools

Sticker Tools Bot @Sticker_Tools_Bot A star ⭐ from you means a lot to us! Telegram bot with various Sticker Tools Usage Deploy to Heroku Tap on above

Stark Bots 20 Dec 08, 2022
A bot can play all variants, but standard are abit weak, so if you need strongest you can change fsf instead of stockfish_14_Dev

MAINTAINERS Drdisrespect1 and drrespectable lichess-bot Engine communication code taken from https://github.com/ShailChoksi/lichess-bot by ShailChoksi

RPNS Nimsilu 1 Dec 12, 2021
This is a walkthrough about understanding the #BoF machine present in the #OSCP exam.

Buffer Overflow methodology Introduction These are 7 simple python scripts and a methodology to ease (not automate !) the exploitation. Each script ta

3isenHeiM 53 Dec 08, 2022
A repository for 8G server's discord bot

8G Discord-Bot A general-purpose discord bot for the 8G Discord-Server To setup: Create a new file called secrets.py and make it look like this TOKEN=

1 Jan 12, 2022
A code that can make an account bump your discord server 24/7!

BumpCord A code that can make an account bump your discord server 24/7! The main.py is the main file. keep_alive.py prevents your repl from going to s

Phantom 28 Aug 20, 2022
A bot written in python that send prefilled Google Forms. It supports multithreading for faster execution time.

GoogleFormsBot https://flassy.xyz https://github.com/Shawey/GoogleFormsBot Requirements: os (Default) ast (Default) threading (Default) configparser (

Shawey 1 Jul 10, 2022
Spodcast is a caching Spotify podcast to RSS proxy

Spodcast Spodcast is a caching Spotify podcast to RSS proxy. Using Spodcast you can follow Spotify-hosted netcasts/podcasts using any player which sup

Frank de Lange 260 Jan 01, 2023
A CLI tool to transfer, sync, and backup playlists on music streaming services

unitunes A command-line interface tool to manage playlists across music streaming services. Introduction unitunes manages playlists across streaming s

Victor Tao 50 Jan 07, 2023
Check AWS S3 instances for read/write/delete access

s3sec Test AWS S3 buckets for read/write/delete access This tool was developed to quickly test a list of s3 buckets for public read, write and delete

0xmoot 114 Dec 06, 2022
Valorant store offer discord-bot

Valorant store checker - Discord Bot Discord bot that shows your daily store offer without open the VALORANT by using the Ingame API. written using Py

STACIA 226 Jan 02, 2023
The most expensive version of Conway's Game of Life - running on the Ethereum Blockchain

GameOfLife The most expensive implementation of Conway's Game of Life ever - over $2,000 per step! (Probably the slowest too!) Conway's Game of Life r

75 Nov 26, 2022
This is an implementation example of a bot that periodically sends predictions to the alphasea-agent.

alphasea-example-model alphasea-example-modelは、 alphasea-agent に対して毎ラウンド、予測を投稿するプログラムです。 Numeraiのexample modelに相当します。 準備 alphasea-example-modelの動作には、

AlphaSea 11 Jul 28, 2022
Kyura-Userbot: a modular Telegram userbot that runs in Python3 with a sqlalchemy database

Kyura-Userbot Telegram Kyura-Userbot adalah userbot Telegram modular yang berjal

Kyura 17 Oct 29, 2022
🪣 Bitbucket Server PAT Generator

🪣 Bitbucket Server PAT Generator 🤝 Introduction Bitbucket Server (nee Stash) can hand out Personal Access Tokens (PAT) to be used in-place of user+p

reecetech 2 May 03, 2022