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.

vagrant-as-infrastructure's People

Contributors

jhriv avatar mcritchlow avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Forkers

mcritchlow

vagrant-as-infrastructure's Issues

Fix group names

Expected Behavior

When using hostnames with dashes, to get automatic groups, there should be no warning

Actual Behavior

[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

Steps to Reproduce the Problem

  1. sample-set as a box name
  2. make all
  3. Profit!

Specifications

  • Version: 1.3.4
  • Platform: macOS Catalina 10.15.7
  • Make version: GNU Make 3.81
  • Vagrant version:Vagrant 2.2.14
  • VirtualBox version: 6.1.16 r140961 (Qt5.6.3)

Can we get a decent .gitignore?

Expected Behavior

Easy to acquire .gitignore

Actual Behavior

Nothing. No where. Keep having to make it up as I go along.

We have Vagrantfile sample. Why not .gitignore? It's not like the machine generated files are a big secret.
They are, what, $(VAIDIR), ansible.cfg, *.log (thank you, Ubuntu), and .vagrant. Could make it a download file or just dump the contents in there, hardcoded in the Makefile.

Steps to Reproduce the Problem

  1. make .gitignore
  2. make: *** No rule to make target .gitignore'. Stop.`
  3. No profit.

Specifications (make versions will collect these)

  • Version: 2.2.2
  • Platform: Darwin 21.3.0
  • Make version: GNU Make 3.81
  • Vagrant version: Vagrant 2.2.19
  • VirtualBox version: 6.1.32r149290

CentOS 7 lacks ip command

Expected Behavior

make ip to work

Actual Behavior

default | CHANGED | rc=0 >>
/bin/sh: ip: command not found

Steps to Reproduce the Problem

  1. make Vagrantifle
  2. DEFAULT_BOX=centos/7 make ip

Specifications (make versions will collect these)

  • Version: 2.2.1
  • Platform: Darwin 21.3.0
  • Make version: GNU Make 3.81
  • Vagrant version: Vagrant 2.2.19
  • VirtualBox version: 6.1.32r149290

Alpine guests won't report their IP address

Expected Behavior

make ip works, even on Alpine

Actual Behavior

hostname: unrecognized option: I

Steps to Reproduce the Problem

  1. GUESTS = [ { name: 'default', box: 'generic/alpine312' } ]
  2. make up
  3. make ip

Specifications

  • Version: 2.1.3
  • Platform: n/a
  • Make version: n/a
  • Vagrant version: n/a
  • VirtualBox version: n/a

No python-apt in Debian 11 (bullseye)

Expected Behavior

Debian Bullseye able to be brought up

Actual Behavior

    debian11: E: Package 'python-apt' has no installation candidate
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

Steps to Reproduce the Problem

  1. Add box: 'debian/bullseye64' to a GUEST.rb defintion
  2. make up
  3. ??
  4. Fail to profit

Specifications

  • Version: 2.1.3
  • Platform: Darwin 21.3.0
  • Make version: GNU Make 3.81
  • Vagrant version: Vagrant 2.2.19
  • VirtualBox version: 6.1.32r149290

make clean leaves empty directories around

Expected Behavior

make cleans up after itself

Actual Behavior

file .vai
.vai: directory

Steps to Reproduce the Problem

  1. make up
  2. make clean

Specifications (make versions will collect these)

  • Version: 2.2.2
  • Platform: Darwin 21.3.0
  • Make version: GNU Make 3.81
  • Vagrant version: Vagrant 2.2.19
  • VirtualBox version: 6.1.32r149290

Rename roles.yml to requirements.yml

Expected Behavior

Be in keepings with the highest traditions of the Ansible ecosystem

Actual Behavior

Being a Burger King

Steps to Reproduce the Problem

  1. make roles

Specifications

  • Version: 1.3.4
  • Platform: Darwin
  • Make version: GNU Make 3.81
  • Vagrant version: Vagrant 2.2.18
  • VirtualBox version: 6.1.26r145957

Add port forwarding

Suggested:
:ports as an array, specifying guest port (required) host port (optional, default to guest port) and auto_correct (optional, default to true)

Should bump minor number

Support "hostname:" option in GUESTS/Vagrantfile

Expected Behavior

Able to set hostname through example Vagrantfile

Actual Behavior

Need to use some other mechanism

Steps to Reproduce Solve the Problem

  1. hostnamectl set-hostname
  2. if guest.has_key?(:hostname)
  3. if guest.hostname.is_a? Boolean (set to guest[:name])
  4. else to the string passed (guest[:hostname])
  5. (optional) ensure guest has hostnamectl (alpine, for instance, doesn't)
  6. (if you opt against) file a bug for improper error conditions not getting trapped
  7. if no hostnamectl, can set /etc/hostname directly
  8. come to think of it, that's not a bad idea after all.
  9. would still need to "reload" the hostname.
  10. probably not - as that login will close and the next login will get the new hostname

Specifications

  • Version: 2.1.3
  • Platform: macOS 12.something
  • Make version: n/a
  • Vagrant version: n/a
  • VirtualBox version: n/a

Update issue template

Expected Behavior

Able to update issue template without warning

Actual Behavior

You are using an old version of issue templates. Please update to the new issue template workflow. Learn more

Steps to Reproduce the Problem

  1. Open the issue template in a browser

Specifications

  • Version: 1.4.0
  • Platform: any
  • Make version: n/a
  • Vagrant version: n/a
  • VirtualBox version: n/a

Allow for running a provisioner

Start with :ansible, allow to specify a playbook to run. Add in others, later, as need arrises. :shell is a good candidate. Open question if both provisioners can work together. Testing may be in order.

{ name: 'default', ansible: 'setup.yml' },
if guest.has.key?(:ansible)
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "guest[:ansible]"
  end
end

Support Alpine

Expected Behavior

It works

Actual Behavior

It doesn't't work. Well, it does but python(3) is missing. So it doesn't entirely work.

Steps to Reproduce the Problem

  1. sensible-editor GUESTS.rb
  2. make all
  3. ???
  4. Profit!

Specifications

  • Version: 1.3.4
  • Platform: macOS Big Sur 11.4
  • Make version: GNU Make 3.81
  • Vagrant version: Vagrant 2.2.16
  • VirtualBox version: Version 6.1.22 r144080 (Qt5.6.3)

Add skel(skeleton) target

Expected Behavior

Create a skeleton directory structure for Ansible management

host_vars/e-host1/main.yml
host_vars/w-host2/main.yml
group_vars/all/main.yml
group_vars/e/main.yml
group_vars/w/main.yml

Where each main.yml contains only a placeholder:

---
# Placeholder

Ideally, built from GUESTS.rb (or the like) and won't adjust any existing files (eg: create if not present)

Actual Behavior

Nada.

Specifications

  • Version: 1.3.4
  • Platform: any
  • Make version: any
  • Vagrant version: any
  • VirtualBox version: any

Support VRDE in Vagrantfile/GUESTS

Expected Behavior

Allow VRDE/RDP without having to use VBoxManage directly

Actual Behavior

Have to use VBoxManage directly

Steps to Reproduce the Problem

  1. make up
  2. VBoxManage modifyvm "VM name" --vrde on
  3. VBoxManage modifyvm "VM name" --vrdeport 5000,5010-5012

Specifications

  • Version: current ?
  • Platform: any
  • Make version: really?
  • Vagrant version: current
  • VirtualBox version: current

Generated group names have illegal characters

Expected Behavior

No warnings when a guest has multiple hyphens in its name

Actual Behavior

[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

Steps to Reproduce the Problem

  1. make Vagrantfile
  2. echo 'GUESTS=[{name:"d-1-a"}]' > GUESTS.rb
  3. make ping

Specifications (make versions will collect these)

  • Version: make version
  • Platform: uname -sr
  • Make version: make --version
  • Vagrant version: vagrant -v
  • VirtualBox version: VBoxManage -v

Issue template checklist is wrong

Expected Behavior

Checklist works

Actual Behavior

It doesn't, unless you do something else

Steps to Reproduce the Problem

  1. Submit PR
  2. Put x in [ ] thingy
  3. oh - it won't render

Specifications

  • Version: 2.2.0

Alpine reports oddball domain for localhost

Expected Behavior

Domainname for localhost be either "localdomain" or absent

Actual Behavior

Varies, depending on install

Steps to Reproduce the Problem

  1. vagrant init generic/alpine312
  2. make ping
  3. ansible all -m setup | grep lavabit.com

Specifications

  • Version: "Latest"
  • Platform:
  • Make version:
  • Vagrant version:
  • VirtualBox version:

Support vbguest option

Expected Behavior

Allow easy addition of VirtualBox Guest Additions

Actual Behavior

not so easy

support libvirt provider

Expected Behavior

Include support in the sample Vagrantfile for the libvirt provider plugin

It looks like the core features I'm aware of that are needed for compatibility are available (but you would know better):

I would expect that it is the responsibility of the end user to ensure the plugin and any related dependencies are installed and functioning properly.

Actual Behavior

I still have to use virtualbox on Linux, which gives me sads.

Add hostname target

Expected Behavior

A guest can set its own hostname via Makefile target

Actual Behavior

Nope.

Steps to Reproduce the Problem

  1. make all
  2. make hostname
  3. fail

Specifications

  • Version: current
  • Platform: all
  • Make version: irrelevant
  • Vagrant version: irrelevant
  • VirtualBox version: irrelevant

Additional Notes:

There's an etc-hosts target. Why not hostname?

Update issue template for instructions on getting requested versions

Expected Behavior

Easy to supply requested information

Actual Behavior

Not as easy to supply requested information

Steps to Reproduce the Problem

  1. Submit a new issue
  2. Look at the Specifications section
  3. Note lack of instruction on how to gather requested information

Specifications

  • Version: 1.4.0
  • Platform: n/a
  • Make version: n/a
  • Vagrant version: n/a
  • VirtualBox version: n/a

Link roles-local/* to roles/

Expected Behavior

Local roles should persist roles clean

Actual Behavior

clean roles is too greed
see issue #5

Steps to Reproduce the Problem

  1. cd roles
  2. ansible-galaxy init foo
  3. cd ..
  4. make clean-roles

Specifications

(not that any of these matter)

  • Version: 1.1.0
  • Platform: Debian Stretch
  • Make version: GNU Make 4.1
  • Vagrant version: 2.2.1
  • VirtualBox version: 5.2.22r126460

Newer Ubuntu comes with Python3

Expected Behavior

Needing to install python

Actual Behavior

Nope! Don't need to!

Will need to determine if Debian ships with Python3 as well.

Need to make a table between Debian/Ubuntu packaged Python and Ansible versions

clean roles too greedy

The clean-roles Makefile target will remove all roles, even ones that were added by hand.

clean-roles should parse the roles.yml and only delete the roles listed therein.

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.