Giter Site home page Giter Site logo

vagrant-as-infrastructure's Introduction

Vagrant as Infrastructure

Inspired by Maxim Chernyak's blog post 6 practices for super smooth Ansible experience

The goal is to produce the convenient local playground, but skipping the ssh key insertion (Vagrant does that for us) and editing /etc/hosts (not available on Windows) while still allowing full access to the guest VMs.

Makefile

Makefile is all you need. Everything else can be downloaded automatically, or use your own personal versions.

Minimal Invocation

Download the Makefile, then

  • make Vagrantfile all

or

  • vagrant init centos/7; make all

Requirements

Optional

Usage

  • make all does the following:
    • make up Brings up all Vagrant boxes (same as vagrant up)
    • make roles Install Ansible Galaxy roles from "requirements.yml" or "config/requirements.yml"
    • make .vai/ssh-config Create ssh configuration
    • make .vai/inventory Create ansible inventory
    • make ansible.cfg Create default ansible.cfg
    • make main Run main.yml playbook, if present
    • make ip Display the IPs of all the VMs*

Other commands:

  • make Vagrantfile Downloads sample Vagrantfile and GUESTS.rb
  • make GUESTS.rb Downloads sample GUESTS.rb (used by sample Vagrantfile)
  • make clean-roles Removes installed ansible roles
  • make clean Removes ansible files
  • make copyright Displays copyright information
  • make etc-hosts Add host records to all guests
  • make license Displays license information
  • make roles-force Update all roles, overwriting when required
  • make ping Pings all guests via Ansible's ping module
  • make python Installs python on Alpine/Debian/Ubuntu systems*
  • make root-key Copies vagrant ssh key for root user access
  • make update Downloads latest version from GitHub*
  • make version Displays installed version

Method

  • Uses a provided or downloaded Vagrantfile to create the application stack systems. See Vagrantfile.sample and GUESTS.rb.sample for a starting point.
  • Install any required Galaxy roles (optional)
  • Write the ssh configuration (as provided by Vagrant)
  • Create ansible.cfg that uses the above ssh configuration

Your Ansible playbooks can now access the Vagrant VMs as if they were a part of your infrastructure, either by name or by group.

Overrides

The Makefile will accept command line options, or read from similarly named environmental variables:

  • ETC_HOSTS etc-hosts playbook*
  • INVENTORY ansible inventory file*
  • MAIN default playbook to run, if present
  • REPO upstream repository
  • RETRYPATH directory to place retry files*
  • ROLES_PATH ansible roles path
  • SAMPLEVAGRANTFILE upstream Vagrantfile.sample
  • SSHCONFIG location of generated ssh configuration*
  • VAIDIR directory to place Ansible files*
  • VAULTPASSWORDFILE path to ansible vault password file*

Roles

If requirements.yml or config/requirements.yml exists, the listed roles will be downloaded from Galaxy. If both exist, then requirements.yml will take precedence.

Manually installed roles can be added to the roles-local directory.

Hosts and Groups

The inventory will group related hosts into groups. Related hosts all share the same prefix. web-1, web-2, web-3 will all be a part of [web].

etc-hosts

Update all guests' /etc/hosts with all other guests' internal networking IPs to allow name-based addressing without relying on external DNS.

Vagrantfile/GUESTS.rb

See README.Vagrantfile.

Semantic Versioning

This project follows SemVer.

Caveats

The ip target may fail on non-Linux guests.

The update target will overwrite the Makefile.

The etc-hosts target works best when there is only one additional interface.

Certain variables, ETC_HOSTS, INVENTORY, ROLES_PATH, SSHCONFIG, VAIDIR, and VAULTPASSWORDFILE will break if there is embedded whitespace.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.