Skip to content

Vagrant example with multi-machine support (and Ansible inventory support) from a variety of config file formats (ini, yaml, json, xml, csv, sqlite3, hosts)

License

Notifications You must be signed in to change notification settings

darkn3rd/vagrant-simple

Repository files navigation

Simple Vagrant Demoes

by Joaquin Menchaca, April 2016

This exercise that demonstrates Vagrant configuration scenarios with a global configuration file. As a bonus, an Ansible dynamic inventory script that sources the same configuration file is provided.

This demonstrates how to parse a configuration file (in INI, YAML, JSON, XML, CSV, SQL, or hosts file formats) in ruby, and bash. amd python languages.

Example Scenarios

Requirements

  • VirtualBox - virtualization system
  • Vagrant - virtualization and provisioning automation tool
  • Ansible (optional) - change configuration tool that can execute commands on vagrant virtual systems.
    • Python - language required by Ansible

For Windows, highly recommend, MSYS2 as it gives you to bash shell and access to tools like git, ssh, curl, and rsync. This is optional.

Note that Ansible is not officially supported on Windows for a workstation (or system used to configure other systems).

OS X

Install Homebrew, Cask, and Brew Bundle, then get other requirements by running:

$ ./install_macosx.sh

Windows

Install Chocolately using command shell (cmd.exe) as Administrator, then run

C:\> choco install chocolately.config
C:\> vagrant plugin install sqlite3
C:\> vagrant plugin install inifile

About this Project

Data Format

The data is a 4D data structure (hash of hash of list of hash) to spice things up. Each section is divided into of configuration area: hosts, defaults, and ports. Thus there may be redundancy.

The provisioning and inventory scripts only care about hosts key, so they'll try to rip this out into arrays to use the data. This is used to configure hosts and ssh_config for ssh and name resolution convenience. For the inventory,this is used to create a JSON file that can be used with ansible or ansible-playbook commands.

Organization

This is what the base file layout looks like, using YAML as an example:

.
├── multimachine-yaml
│   ├── README.md
│   ├── Vagrantfile        # main ansible configuration
│   ├── config
│   │   ├── global.yaml    # global configuration
│   │   └── inventory.py   # ansinble inventory script, must be next to config
│   └── scripts
│       ├── baselib.src    # local copy of baselib.sh
│       ├── client.sh      # provisioning script
│       ├── master.sh      # provisioning script
│       ├── setup-base.sh  # base provisioning script for ssh_config and hosts
│       ├── slave.sh       # provisioning script
│       ├── slave1.sh -> slave.sh # symlink to common provisioning script
│       └── slave2.sh -> slave.sh # symlink to common provisioning script
└── scriptlib
    ├── baselib.sh         # main shell provisioning library
    ├── common.vagrantfile # common base vagrantfile that uses settings hash
    └── yaml.rb            # creates settings hash from ruby

Final Notes

MSYS2

MSYS2 is a light minimalist bash environment for Windows, similar to MSYS that comes with MinGW (Minimalist GNU for Windows ) and Git-Bash tools, except that it is 64-bit. If you use advanced features like rsync, then you'll need a 64-bit rsync solution.

After installing MSYS2, e.g. choco install msys2, run:

$ pacman --needed -Sy bash pacman pacman-mirrors msys2-runtime

Close and restart MSYS2 and run:

$ pacman -Su
$ # other tools (optional)
$ pacman -S rsync
$ pacman -S git
$ pacman -S curl

Research Links

These are some topics I came across while researching Vagrant, Ruby libraries and shell command-line tools and scripts:

License

The content of this project itself is licensed under the Creative Commons Attribution 3.0 license, and the underlying source code is licensed under the MIT license.

About

Vagrant example with multi-machine support (and Ansible inventory support) from a variety of config file formats (ini, yaml, json, xml, csv, sqlite3, hosts)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published