• Stars
    star
    129
  • Rank 277,641 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vagrant Box Templates

Purpose

Spin up different OS types using Vagrant and learn Ansible at the same time if desired. Some distros also include Desktop versions.

Requirements

Software

Alpine box requirements

vagrant-alpine plugin

NOTE: require the vagrant-alpine plugin to be installed

vagrant plugin install vagrant-alpine

/vagrant synced_folder

NOTE: NFS is used for the /vagrant synced_folder. This means you will be prompted for sudo password when spinning up a box. This can be changed to not prompt by references here

Setting up sudoers

OS X

To setup sudoers for OSX add the following using visudo

Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports
%admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE
Ubuntu

To setup sudoers for Ubuntu add the following using visudo

Cmnd_Alias VAGRANT_EXPORTS_CHOWN = /bin/chown 0\:0 /tmp/*
Cmnd_Alias VAGRANT_EXPORTS_MV = /bin/mv -f /tmp/* /etc/exports
Cmnd_Alias VAGRANT_NFSD_CHECK = /etc/init.d/nfs-kernel-server status
Cmnd_Alias VAGRANT_NFSD_START = /etc/init.d/nfs-kernel-server start
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
%sudo ALL=(root) NOPASSWD: VAGRANT_EXPORTS_CHOWN, VAGRANT_EXPORTS_MV, VAGRANT_NFSD_CHECK, VAGRANT_NFSD_START, VAGRANT_NFSD_APPLY
Fedora

To setup sudoers for Fedora add the following using visudo

Note: Given your user belongs to the vagrant group

Cmnd_Alias VAGRANT_EXPORTS_CHOWN = /bin/chown 0\:0 /tmp/*
Cmnd_Alias VAGRANT_EXPORTS_MV = /bin/mv -f /tmp/* /etc/exports
Cmnd_Alias VAGRANT_NFSD_CHECK = /usr/bin/systemctl status --no-pager nfs-server.service
Cmnd_Alias VAGRANT_NFSD_START = /usr/bin/systemctl start nfs-server.service
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
%vagrant ALL=(root) NOPASSWD: VAGRANT_EXPORTS_CHOWN, VAGRANT_EXPORTS_MV, VAGRANT_NFSD_CHECK, VAGRANT_NFSD_START, VAGRANT_NFSD_APPLY

Included Box Distros

NOTE: This list may not be completely up to date.

Below are the included distros along with their respective releases that are available in this repo.

Distro Releases
Alpine 3.7, 3.8, 3.9, 3.10
Arch N/A
CentOS 5, 6, 7, 8
Debian 7, 8, 9, 10
Fedora 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
FreeNAS 11.2
LinuxMint 18, 19
openSUSE 15.0, 15.1, 42.2, 42.3
Oracle Linux 7
Scientific-Linux 7
Ubuntu 12.04, 14.04, 15.04, 15.10, 16.04, 16.10, 17.04, 17.10, 18.04, 18.10, 19.04, 19.10
VyOS 1.1.8
Windows 10, 2008 R2, 2012 R2, 2016, 2019

Useful information

Building Vagrant Boxes

My process for building and keeping the majority of these boxes up to date is by using Packer. I also maintain a Packer Templates repository which contains all of the relevant information on how build and test new boxes.

Vagrantfile

A single Vagrantfile is used for all distros to use. This helps keeping changes to a minimum (Very seldom needed). The reason behind this is that I have spent close to two years trying to come up with a single Vagrantfile that would fit most any scenario that I have a use case for during development. Many of these scenarios involve multinode clustering, routing, loadbalancing, ZFS, GlusterFS, Docker Swarm, Kubernetes, ELK Stack, and so on. Not to say that a specific use case may not present itself that would require a change to the Vagrantfile but those are far in between.

Vagrantfile

File structure

Most files are symlinks from each distro folder into the repo root to keep a consistent and easy method of changing things around. Feel free to change as needed.

Working on different projects

One trick that I use daily with these templates is to working on many different projects and not ever need to change out of my single folder. What I mean by this is that I can stay within a single folder and easily switch between projects by using GIT branches for each project.

Create development environment

  1. Clone this repo
cd ~
mkdir -p projects/vagrant
cd projects/vagrant
git clone https://github.com/mrlesmithjr/vagrant-box-templates
  1. Remove the origin remote
cd vagrant-box-templates
git remote remove origin
  1. Add this repo as the upstream remote
git remote add upstream https://github.com/mrlesmithjr/vagrant-box-templates.git
git fetch upstream master

At this point you now are on your local master branch with a remote called upstream.

Create project development environment

I never do any work in master to keep this nice and untouched. So when I need to work on a project I simply do the following:

git checkout master
git checkout -b projectname

I then define my environment, Ansible groups, Ansible roles, and Ansible playbooks for the specific project. I then do all of my testing and development, and when I am finished, I simply add all of the new/changed files and commit them only locally. Then the next time I need a new environment I follow this same process by going back to master and checking out another branch for developing in.

NOTE: You could definitely add another GIT remote and keep your projects (branches) synced.

Example of what my current environment looks like after cleaning it up a bit not long ago.

  dev/alpine-docker
  dev/apache2
  dev/bird
  dev/bro-ids
  dev/cacti
  dev/ceph
  dev/config-interfaces
  dev/dnsmasq
  dev/docker
  dev/dumb-init
  dev/elasticsearch
  dev/eve-ng
  dev/fluentd
  dev/gerrit
  dev/graylog
  dev/influxdb
  dev/k8s
  dev/kea-dhcp
  dev/kvm
  dev/landscape
  dev/letsencrypt
  dev/lvm
  dev/monit
  dev/motd
  dev/mysql
  dev/netdata
  dev/pdns
  dev/postgres
  dev/prometheus-grafana-docker
  dev/rabbitmq
  dev/sensu
  dev/spinnaker
  dev/squid-haproxy-keepalived
  dev/stackstorm
  dev/syslog-ng
  dev/testing-roles
  dev/tripwire
  dev/unbound
  dev/vault-consul
  dev/vault-consul-docker
  dev/vault-consul-docker-monitoring
  dev/zabbix
  issue-#9
* master
  play/linuxmint
  play/zesty-desktop
  test/uname
  testing/consul

Keeping development environment up to date with this repo

In order to keep my development environment synced up with any changes from this repo all I have to do is:

git checkout master
git fetch upstream master
git pull --rebase upstream master

And now if I want to pull any important changes into any existing projects I simply have to only do:

git checkout projectname
git rebase master

Using Docker containers

You may also be interested in using Docker containers to perform similar testing scenarios as we are doing here. We can still use Vagrant and Ansible as we do here but we replace Virtualbox with Docker as our provider. This definitely keeps things slimmed down a bit but does limit some of our testing scenarios. However, if you are interested in this you can also checkout my vagrant-container-templates repo for more info on that.

Usage

Getting started

Clone repo

git clone https://github.com/mrlesmithjr/vagrant-box-templates
cd vagrant-box-templates

Choose distro

Find the OS of your choice and spin up a node or more.

Customizing environment

Each distro folder contains a environment.yml file which you can change the number of nodes to spin up if desired.

For examples of possible settings checkout the following test environment: Test/dummy/server/environment.yml

Nested Virtualization

You can enable nested virtualization by defining/modifying the nested_virtualization parameter in a node definition. This currently ONLY works on VMware boxes.

Disks, interfaces, and port_forwards

If you would like to change disks|interfaces|port_forwards feel free to uncomment those sections and adjust them as needed.

Provisioning

If you would like to provision the nodes when they startup you will need to set provision: true in the environment.yml. Also if the box that is to be spun up is Windows based then set windows: true in order for provisioning specific to Windows to occur.

By default the following provisioning will occur:

You may also define custom provisioners either globally or per node to be executed during provisioning.

To define global provisioners, simply edit the environment.yml file and use the following as an example:

# Global provisioners
provisioners:
  - type: shell
    inline: |
      if [ -f /etc/os-release ]; then
          os_name="$(awk -F= '/^NAME/{ print $2 }' /etc/os-release | sed 's/"//g')"
          os_version_id="$(awk -F= '/^VERSION_ID/{ print $2}' /etc/os-release | sed 's/"//g')"
          echo $os_name
          echo $os_version_id
      fi
    privileged: true
  # - type: shell
  #   path:
  #     - scripts/test.sh
  #   privileged: false
  # - type: ansible
  #   playbooks:
  #     - test.yml

When it comes to per node provisioning, currently only scripts and ansible_local are supported. Ansible playbook provisioners are easy enough to define which nodes should be executed against already.

To define per node provisioners, use the below as an example to use within the environment.yml file:

nodes:
  - name: node0
    ansible_groups:
      - test_nodes
    box: mrlesmithjr/bionic64
    desktop: false
    disks: []
    interfaces: []
    linked_clone: true
    mem: 512
    provision: true
    # Node specific provisioners
    provisioners:
      # - type: shell
      #   inline: |
      #       if [ -f /etc/os-release ]; then
      #           os_name="$(awk -F= '/^NAME/{ print $2 }' /etc/os-release | sed 's/"//g')"
      #           os_version_id="$(awk -F= '/^VERSION_ID/{ print $2}' /etc/os-release | sed 's/"//g')"
      #           echo $os_name
      #           echo $os_version_id
      #       fi
      #   privileged: true
      - type: shell
        path:
          - scripts/test.sh
        privileged: false
    vcpu: 1
    port_forwards: []
    windows: false
Linked Clones

By default, all VMs are configured to be spun up as linked clones. This is the default to keep disk space to a minimum. You can easily change a VM to either be a linked clone or not by changing or adding the linked_clone: true or linked_clone: false to the environment.yml file in the respective distro folder:

Spinning up environment

When you are ready to spin up your environment simply:

vagrant up
Example Ubuntu Trusty environment

For example if I want to spin up a Ubuntu Trusty server node:

cd vagrant-box-templates/Ubuntu/trusty64/server
vagrant up
vagrant ssh

Tearing down environment

When you are all done with your Vagrant environment you can quickly and cleanly tear it all down:

Non-Windows:

    ./scripts/cleanup.sh

Windows:

    cleanup.bat

Unit tests

If you are interested in using these templates for unit testing I have included a beginning script which can be used for spinning up a box or boxes to conduct unit testing. The current main focus on this is to spin up the boxes, provision them based on the roles defined in playbook.yml, test idempotency and then tear everything down. This script will create a logs directory which will contain all of the output collected from the unit test. This is not perfect at this time but it does work fairly well for basic testing. I will be adding more functionality over time and definitely welcome feedback.

Executing unit tests

In order to effectively conduct a unit test all you need to do is adjust the environment.yml file and define your nodes, ensure provision: true is defined, define the roles in playbook.yml and then:

./unit-test.sh

And then let the script do all of the work and record the results.

Example unit test results

Below is an example output from a unit test:

ansible 2.3.1.0
  config file = /Users/larry/projects/vagrant/vagrant-box-templates/Ubuntu/xenial64/server/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Apr  4 2017, 08:47:57) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)]
ANSIBLE0013 Use shell only when shell functionality is required
/Users/larry/Git_Projects/GitHub/mrlesmithjr/ansible-base/handlers/main.yml:3
Task/Handler: update resolvconf

 [WARNING]: Host file not found: /etc/ansible/hosts
 [WARNING]: provided hosts list is empty, only localhost is available

playbook: playbook.yml
Bringing machine 'node0' up with 'virtualbox' provider...
==> node0: Importing base box 'mrlesmithjr/xenial64'...

οΏ½[KProgress: 10%
οΏ½[KProgress: 20%
οΏ½[KProgress: 30%
οΏ½[KProgress: 40%
οΏ½[KProgress: 50%
οΏ½[KProgress: 60%
οΏ½[KProgress: 70%
οΏ½[KProgress: 80%
οΏ½[KProgress: 90%
οΏ½[K==> node0: Matching MAC address for NAT networking...
==> node0: Checking if box 'mrlesmithjr/xenial64' is up to date...
==> node0: Setting the name of the VM: server_node0_1498705353100_6863
==> node0: Clearing any previously set network interfaces...
==> node0: Preparing network interfaces based on configuration...
    node0: Adapter 1: nat
    node0: Adapter 2: hostonly
==> node0: Forwarding ports...
    node0: 22 (guest) => 2222 (host) (adapter 1)
==> node0: Running 'pre-boot' VM customizations...
==> node0: Booting VM...
==> node0: Waiting for machine to boot. This may take a few minutes...
    node0: SSH address: 127.0.0.1:2222
    node0: SSH username: vagrant
    node0: SSH auth method: private key
    node0:
    node0: Vagrant insecure key detected. Vagrant will automatically replace
    node0: this with a newly generated keypair for better security.
    node0:
    node0: Inserting generated public key within guest...
    node0: Removing insecure key from the guest if it's present...
    node0: Key inserted! Disconnecting and reconnecting using new SSH key...
==> node0: Machine booted and ready!
==> node0: Checking for guest additions in VM...
==> node0: Setting hostname...
==> node0: Configuring and enabling network interfaces...
==> node0: Mounting shared folders...
    node0: /vagrant => /Users/larry/projects/vagrant/vagrant-box-templates/Ubuntu/xenial64/server
==> node0: Running provisioner: shell...
    node0: Running: /var/folders/x5/wbmc7zqj1nv4cnjxjqls86sh0000gn/T/vagrant-shell20170628-82789-jpoks9.sh
==> node0: Hit:1 http://us.archive.ubuntu.com/ubuntu xenial InRelease
==> node0: Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
==> node0: Get:3 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
==> node0: Get:4 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
==> node0: Get:5 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [568 kB]
==> node0: Get:6 http://us.archive.ubuntu.com/ubuntu xenial-updates/main i386 Packages [549 kB]
==> node0: Get:7 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [294 kB]
==> node0: Get:8 http://us.archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [230 kB]
==> node0: Get:9 http://us.archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [7,772 B]
==> node0: Get:10 http://us.archive.ubuntu.com/ubuntu xenial-updates/restricted i386 Packages [7,772 B]
==> node0: Get:11 http://us.archive.ubuntu.com/ubuntu xenial-updates/restricted Translation-en [2,548 B]
==> node0: Get:12 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [490 kB]
==> node0: Get:13 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe i386 Packages [471 kB]
==> node0: Get:14 http://security.ubuntu.com/ubuntu xenial-security/main i386 Packages [278 kB]
==> node0: Get:15 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [194 kB]
==> node0: Get:16 http://us.archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [8,932 B]
==> node0: Get:17 http://us.archive.ubuntu.com/ubuntu xenial-updates/multiverse i386 Packages [7,992 B]
==> node0: Get:18 http://us.archive.ubuntu.com/ubuntu xenial-updates/multiverse Translation-en [4,460 B]
==> node0: Get:19 http://us.archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [4,688 B]
==> node0: Get:20 http://us.archive.ubuntu.com/ubuntu xenial-backports/main i386 Packages [4,692 B]
==> node0: Get:21 http://us.archive.ubuntu.com/ubuntu xenial-backports/main Translation-en [3,216 B]
==> node0: Get:22 http://us.archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [5,804 B]
==> node0: Get:23 http://us.archive.ubuntu.com/ubuntu xenial-backports/universe i386 Packages [5,812 B]
==> node0: Get:24 http://us.archive.ubuntu.com/ubuntu xenial-backports/universe Translation-en [3,004 B]
==> node0: Get:25 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [125 kB]
==> node0: Get:26 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [7,420 B]
==> node0: Get:27 http://security.ubuntu.com/ubuntu xenial-security/restricted i386 Packages [7,420 B]
==> node0: Get:28 http://security.ubuntu.com/ubuntu xenial-security/restricted Translation-en [2,428 B]
==> node0: Get:29 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [140 kB]
==> node0: Get:30 http://security.ubuntu.com/ubuntu xenial-security/universe i386 Packages [125 kB]
==> node0: Get:31 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [72.7 kB]
==> node0: Get:32 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [2,748 B]
==> node0: Get:33 http://security.ubuntu.com/ubuntu xenial-security/multiverse i386 Packages [2,908 B]
==> node0: Fetched 3,934 kB in 1s (2,118 kB/s)
==> node0: Reading package lists...
==> node0: Reading package lists...
==> node0: Building dependency tree...
==> node0: Reading state information...
==> node0: The following additional packages will be installed:
==> node0:   libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python2.7
==> node0:   python2.7-minimal
==> node0: Suggested packages:
==> node0:   python-doc python-tk python2.7-doc binfmt-support
==> node0: The following NEW packages will be installed:
==> node0:   libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python
==> node0:   python-minimal python2.7 python2.7-minimal
==> node0: 0 upgraded, 7 newly installed, 0 to remove and 93 not upgraded.
==> node0: Need to get 3,915 kB of archives.
==> node0: After this operation, 16.6 MB of additional disk space will be used.
==> node0: Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpython2.7-minimal amd64 2.7.12-1ubuntu0~16.04.1 [339 kB]
==> node0: Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 python2.7-minimal amd64 2.7.12-1ubuntu0~16.04.1 [1,295 kB]
==> node0: Get:3 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 python-minimal amd64 2.7.11-1 [28.2 kB]
==> node0: Get:4 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpython2.7-stdlib amd64 2.7.12-1ubuntu0~16.04.1 [1,884 kB]
==> node0: Get:5 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 python2.7 amd64 2.7.12-1ubuntu0~16.04.1 [224 kB]
==> node0: Get:6 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libpython-stdlib amd64 2.7.11-1 [7,656 B]
==> node0: Get:7 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 python amd64 2.7.11-1 [137 kB]
==> node0: dpkg-preconfigure: unable to re-open stdin: No such file or directory
==> node0: Fetched 3,915 kB in 1s (2,962 kB/s)
==> node0: Selecting previously unselected package libpython2.7-minimal:amd64.
==> node0: (Reading database ...
==> node0: (Reading database ... 5%
==> node0: (Reading database ... 10%
==> node0: (Reading database ... 15%
==> node0: (Reading database ... 20%
==> node0: (Reading database ... 25%
==> node0: (Reading database ... 30%
==> node0: (Reading database ... 35%
==> node0: (Reading database ... 40%
==> node0: (Reading database ... 45%
==> node0: (Reading database ... 50%
==> node0: (Reading database ... 55%
==> node0: (Reading database ... 60%
==> node0: (Reading database ... 65%
==> node0: (Reading database ... 70%
==> node0: (Reading database ... 75%
==> node0: (Reading database ... 80%
==> node0: (Reading database ... 85%
==> node0: (Reading database ... 90%
==> node0: (Reading database ... 95%
==> node0: (Reading database ... 100%
==> node0: (Reading database ...
==> node0: 70600 files and directories currently installed.)
==> node0: Preparing to unpack .../libpython2.7-minimal_2.7.12-1ubuntu0~16.04.1_amd64.deb ...
==> node0: Unpacking libpython2.7-minimal:amd64 (2.7.12-1ubuntu0~16.04.1) ...
==> node0: Selecting previously unselected package python2.7-minimal.
==> node0: Preparing to unpack .../python2.7-minimal_2.7.12-1ubuntu0~16.04.1_amd64.deb ...
==> node0: Unpacking python2.7-minimal (2.7.12-1ubuntu0~16.04.1) ...
==> node0: Selecting previously unselected package python-minimal.
==> node0: Preparing to unpack .../python-minimal_2.7.11-1_amd64.deb ...
==> node0: Unpacking python-minimal (2.7.11-1) ...
==> node0: Selecting previously unselected package libpython2.7-stdlib:amd64.
==> node0: Preparing to unpack .../libpython2.7-stdlib_2.7.12-1ubuntu0~16.04.1_amd64.deb ...
==> node0: Unpacking libpython2.7-stdlib:amd64 (2.7.12-1ubuntu0~16.04.1) ...
==> node0: Selecting previously unselected package python2.7.
==> node0: Preparing to unpack .../python2.7_2.7.12-1ubuntu0~16.04.1_amd64.deb ...
==> node0: Unpacking python2.7 (2.7.12-1ubuntu0~16.04.1) ...
==> node0: Selecting previously unselected package libpython-stdlib:amd64.
==> node0: Preparing to unpack .../libpython-stdlib_2.7.11-1_amd64.deb ...
==> node0: Unpacking libpython-stdlib:amd64 (2.7.11-1) ...
==> node0: Processing triggers for man-db (2.7.5-1) ...
==> node0: Processing triggers for mime-support (3.59ubuntu1) ...
==> node0: Setting up libpython2.7-minimal:amd64 (2.7.12-1ubuntu0~16.04.1) ...
==> node0: Setting up python2.7-minimal (2.7.12-1ubuntu0~16.04.1) ...
==> node0: Linking and byte-compiling packages for runtime python2.7...
==> node0: Setting up python-minimal (2.7.11-1) ...
==> node0: Selecting previously unselected package python.
==> node0: (Reading database ...
==> node0: (Reading database ... 5%
==> node0: (Reading database ... 10%
==> node0: (Reading database ... 15%
==> node0: (Reading database ... 20%
==> node0: (Reading database ... 25%
==> node0: (Reading database ... 30%
==> node0: (Reading database ... 35%
==> node0: (Reading database ... 40%
==> node0: (Reading database ... 45%
==> node0: (Reading database ... 50%
==> node0: (Reading database ... 55%
==> node0: (Reading database ... 60%
==> node0: (Reading database ... 65%
==> node0: (Reading database ... 70%
==> node0: (Reading database ... 75%
==> node0: (Reading database ... 80%
==> node0: (Reading database ... 85%
==> node0: (Reading database ... 90%
==> node0: (Reading database ... 95%
==> node0: (Reading database ... 100%
==> node0: (Reading database ...
==> node0: 71347 files and directories currently installed.)
==> node0: Preparing to unpack .../python_2.7.11-1_amd64.deb ...
==> node0: Unpacking python (2.7.11-1) ...
==> node0: Processing triggers for man-db (2.7.5-1) ...
==> node0: Setting up libpython2.7-stdlib:amd64 (2.7.12-1ubuntu0~16.04.1) ...
==> node0: Setting up python2.7 (2.7.12-1ubuntu0~16.04.1) ...
==> node0: Setting up libpython-stdlib:amd64 (2.7.11-1) ...
==> node0: Setting up python (2.7.11-1) ...
==> node0: Running provisioner: ansible...
    node0: Running ansible-playbook...

PLAY [all] *********************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node0]

TASK [Updating Apt Cache (Debian)] *********************************************
ok: [node0]

TASK [Installing Ansible Pre-Reqs (Alpine)] ************************************
skipping: [node0] => (item=[])

TASK [Installing Python Packages (Alpine)] *************************************
skipping: [node0] => (item=[])

TASK [Installing Python Packages (Alpine)] *************************************
skipping: [node0] => (item=[])

TASK [Installing Ansible Pre-Reqs (Debian)] ************************************
changed: [node0] => (item=[u'build-essential', u'libffi-dev', u'libssl-dev', u'python-dev', u'python-pip', u'python-setuptools'])

TASK [Installing EPEL Repo (RedHat)] *******************************************
skipping: [node0]

TASK [Installing Ansible Pre-Reqs (RedHat)] ************************************
skipping: [node0] => (item=[])

TASK [Installing Ansible Pre-Reqs (Fedora)] ************************************
skipping: [node0]

TASK [Installing Ansible Pre-Reqs (Fedora)] ************************************
skipping: [node0] => (item=[])

TASK [Installing Ansible Pre-Reqs (openSUSE)] **********************************
skipping: [node0] => (item=[])

TASK [Updating Python Modules] *************************************************
changed: [node0] => (item=pip)
changed: [node0] => (item=cffi)

TASK [Installing Ansible] ******************************************************
changed: [node0]

TASK [Ensuring host_vars Directory Exists] *************************************
changed: [node0 -> localhost]

TASK [Ensuring Host File Exists In host_vars] **********************************
ok: [node0 -> localhost]

TASK [Creating Missing host_vars] **********************************************
changed: [node0 -> localhost]

TASK [Updating ansible_ssh_host] ***********************************************
skipping: [node0]

TASK [Updating ansible_ssh_host] ***********************************************
changed: [node0 -> localhost]

TASK [Capturing eth1 IP Address (Alpine)] **************************************
skipping: [node0]

TASK [Updating ansible_ssh_host (Alpine)] **************************************
skipping: [node0]

TASK [Updating ansible_ssh_port] ***********************************************
changed: [node0 -> localhost]

TASK [Updating ansible_ssh_key] ************************************************
changed: [node0 -> localhost]

TASK [Ensuring host_vars Is YAML Formatted] ************************************
changed: [node0 -> localhost]

PLAY RECAP *********************************************************************
node0                      : ok=12   changed=9    unreachable=0    failed=0

==> node0: Running provisioner: ansible...
    node0: Running ansible-playbook...

PLAY [test_nodes] **************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node0]

TASK [ansible-base : debian | running apt-get update] **************************
ok: [node0]

TASK [ansible-base : debian | running apt-get update (forced)] *****************
skipping: [node0]

TASK [ansible-base : debian | installing base packages] ************************
changed: [node0] => (item=[u'build-essential', u'software-properties-common', u'curl', u'git', u'git-core', u'ntp', u'scsitools'])

TASK [ansible-base : debian | resetting /etc/dhcp/dhclient.conf to default] ****
skipping: [node0]

TASK [ansible-base : debian_update_dns_nameservers | setting dns nameservers] ***
skipping: [node0]

TASK [ansible-base : debian | setting dns search suffix] ***********************
skipping: [node0]

TASK [ansible-base : redhat | installing base packages] ************************
skipping: [node0] => (item=[])

TASK [ansible-base : redhat | installing base packages] ************************
skipping: [node0] => (item=[])

TASK [ansible-dnsmasq : alpine | Installing DNSMasq] ***************************
skipping: [node0]

TASK [ansible-dnsmasq : debian | Installing DNSMasq] ***************************
changed: [node0]

TASK [ansible-dnsmasq : redhat | Installing DNSMasq] ***************************
skipping: [node0]

TASK [ansible-dnsmasq : redhat | Installing DNSMasq] ***************************
skipping: [node0]

TASK [ansible-dnsmasq : redhat | Ensuring DNSMasq Service is Enabled and Started] ***
skipping: [node0]

TASK [ansible-dnsmasq : opensuse | Installing DNSMasq] *************************
skipping: [node0]

TASK [ansible-dnsmasq : opensuse | Ensuring DNSMasq Service Is Enabled and Started] ***
skipping: [node0]

TASK [ansible-dnsmasq : dnsmasq_config | Configuring DNSMasq] ******************
changed: [node0]

TASK [ansible-dnsmasq : dnsmasq_config | Ensuring /var/lib/tftpboot Exists] ****
skipping: [node0]

RUNNING HANDLER [ansible-dnsmasq : restart dnsmasq] ****************************
changed: [node0]

PLAY RECAP *********************************************************************
node0                      : ok=6    changed=4    unreachable=0    failed=0

Idempotence test: pass
==> node0: Forcing shutdown of VM...
==> node0: Destroying VM and associated drives...

Learning Ansible

If you are interested in learning Ansible ensure that Ansible is installed on your host machine.

Ansible Groups

If you need to create different Ansible groups for your project all you need to do is edit the environment.yml. For example if I am working on a project for Docker Swarm I might want to separate out my nodes by Swarm Managers and Swarm Workers. So I would something similar to below:

environment.yml:

- name: "node0"
  ansible_groups:
    - "swarm_managers"
  box: "mrlesmithjr/xenial64"
  desktop: false
  # disks:
  #   - size: 10
  #     controller: "SATA Controller"
  #   - size: 10
  #     controller: "SATA Controller"
  interfaces:
    - ip: 192.168.250.10
      auto_config: true
      method: "static"
  #   - ip: 192.168.1.10
  #     auto_config: false
  #     method: 'static'
  #     network_name: 'network-1'
  linked_clone: true
  mem: 512
  provision: true
  vcpu: 1
  # port_forwards:
  #   - guest: 80
  #     host: 8080
  #   - guest: 443
  #     host: 4433
- name: "node1"
  ansible_groups:
    - "docker_swarm_workers"
  box: "mrlesmithjr/xenial64"
  desktop: false
  # disks:
  #   - size: 10
  #     controller: "SATA Controller"
  #   - size: 10
  #     controller: "SATA Controller"
  interfaces:
    - ip: 192.168.250.11
      auto_config: true
      method: "static"
  #   - ip: 192.168.1.10
  #     auto_config: false
  #     method: 'static'
  #     network_name: 'network-1'
  linked_clone: true
  mem: 512
  provision: true
  vcpu: 1
  # port_forwards:
  #   - guest: 80
  #     host: 8080
  #   - guest: 443
  #     host: 4433

And that would be all you need to do and those groups would be created when we do a vagrant up. As you can see there were no changes required in the Vagrantfile to make this all happen. And you will be able to define your playbook as you normally would.

Ansible playbooks

Within in the playbooks directory there is an included playbook.yml file to use as a skeleton playbook. This playbook is always executed when provisioning. So, you may want to just modify this playbook to suit your needs. However, you may create additional playbooks or leverage existing ones by adapting your environment.yml within the distro folders.

Ansible requirements.yml

Within the root folder there is also an included requirements.yml file which includes some basics Ansible roles that can be installed to get an understanding of using this method.

Installing Ansible roles
Global Ansible roles installation

If you would like to install the Ansible roles globally on your host machine you can do so by:

sudo ansible-galaxy install -r requirements.yml
Non-Global Ansible roles installation

If you would like to install the Ansible roles in the current directory in a specific distro version you can do so by:

For example for Ubuntu Xenial:

cd vagrant-box-templates/Ubuntu/xenial64/server
ansible-galaxy install -r requirements.yml -p ./roles
Using existing folder of Ansible roles

If you have an existing folder which includes some Ansible roles you can very easily leverage those as well.

TIP: This is something that I do for development of roles.

Simply edit the included ansible.cfg file and change the following:

From:

# additional paths to search for roles in, colon separated
#roles_path    = /etc/ansible/roles

To:

# additional paths to search for roles in, colon separated
roles_path    = /etc/ansible/roles:~/Git_Projects/GitHub/mrlesmithjr:roles

License

MIT

Author Information

Larry Smith Jr.

Buy Me A Coffee

More Repositories

1

Ansible

Python
167
star
2

ansible-rpi-k8s-cluster

Deploy Raspberry Pi Kubernetes cluster using Ansible
Jinja
144
star
3

packer-templates

Shell
133
star
4

ansible-netplan

Ansible role to manage Netplan
Jinja
128
star
5

ansible-mariadb-galera-cluster

Jinja
126
star
6

graylog2

Shell
119
star
7

ansible-vsphere-management

Python
81
star
8

Packer-For-vSphere-and-More

Shell
77
star
9

ansible-netdata

An Ansible role to install/configure Netdata
Jinja
76
star
10

ansible-manage-lvm

Ansible role to manage LVM Groups/Logical Volumes
Python
76
star
11

Logstash_Kibana3

Shell
60
star
12

ansible-mdadm

Jinja
54
star
13

ansible-kvm

Jinja
51
star
14

ansible-rabbitmq

Ansible role to install/configure RabbitMQ
Erlang
46
star
15

ansible-zfs

Installs and configures ZFS On Linux
Shell
44
star
16

ansible-frr

Jinja
37
star
17

packer-templates-revisited

Shell
36
star
18

cacti

This repo will contain some of my templates and other goodies
36
star
19

ansible-config-interfaces

Jinja
33
star
20

ansible-samba

Jinja
32
star
21

ansible-nginx-load-balancer

Python
23
star
22

cookiecutter-ansible-role

A cookiecutter project template for Ansible roles
22
star
23

ansible-maas

An Ansible role to install/configure MAAS
22
star
24

ansible-openldap

Jinja
21
star
25

vagrant-ansible-routing-template

Python
21
star
26

dotfiles

Shell
21
star
27

vagrant-vault-consul-docker-monitoring

Shell
20
star
28

ansible-drbd

Jinja
20
star
29

ansible-opennms

Jinja
20
star
30

ansible-squid

Ansible role to install/configure Squid Proxy
Jinja
20
star
31

ansible-guacamole

Ansible role to install/configure Guacamole
Jinja
19
star
32

vagrant-ansible-docker-swarm

Python
19
star
33

ansible-dnsmasq

Enter description of Ansible role
Jinja
18
star
34

developers-workstation-setup

Shell
17
star
35

ansible-pacemaker

Jinja
16
star
36

terraform-to-ansible

Terraform to Ansible - Consume Terraform State as Ansible Inventory
Python
16
star
37

ansible-ipset

Jinja
16
star
38

ansible-k8s

HTML
15
star
39

ansible-docker

Enter description of Ansible role
Jinja
15
star
40

ansible-snort

Shell
14
star
41

ansible-kea-dhcp

14
star
42

ansible-motd

Shell
14
star
43

ansible-apt-sources

Enter description of Ansible role
Jinja
14
star
44

ansible-freenas

An Ansible role to manage FreeNAS
14
star
45

ansible-elkstack

Shell
14
star
46

ansible-cloud-init

Jinja
14
star
47

python-powerdns-management

Jinja
13
star
48

ansible-suricata

Shell
12
star
49

ansible-cmdb

PLpgSQL
12
star
50

ansible-control-machine

12
star
51

packer-builder

Packer Builder - Making Packer Building More Consumable
Python
11
star
52

ansible-logstash

11
star
53

ansible-manage-ssh-keys

11
star
54

ansible-chrony

Ansible role to install/configure Chrony
Jinja
11
star
55

ansible-glusterfs

Jinja
11
star
56

ansible-shorewall

10
star
57

hashi-learning

Shell
10
star
58

ansible-nfs-server

Jinja
10
star
59

ansible-prometheus

Ansible role to install/configure Prometheus
Jinja
10
star
60

ansible-stackstorm

Ruby
10
star
61

ansible-base

HTML
9
star
62

ansible-mongodb

8
star
63

ansible-apt-mirror

Jinja
8
star
64

ansible-windows-remote-desktop

8
star
65

terraform-builder

Terraform Builder - Build consistent Terraform configurations
Python
8
star
66

ansible-consul

Ansible role to install/configure Consul
Jinja
8
star
67

ansible-isc-dhcp

8
star
68

ansible-elasticsearch

An Ansible role to install/configure Elasticsearch
Jinja
8
star
69

ansible-kata-containers

Shell
8
star
70

ansible-openvswitch

8
star
71

vagrant-ansible-gerrit-lab

Shell
8
star
72

ansible-quagga

Shell
7
star
73

ansible-gerrit

7
star
74

ansible-windows-domain-controller

7
star
75

ansible-rundeck

Jinja
7
star
76

netbox

Ansible collection for installing/configuring/managing NetBox
Python
7
star
77

ansible-apache2

Jinja
7
star
78

docker-phpipam

PHP
7
star
79

vagrant-container-templates

Shell
7
star
80

sync-forked-repo

Python
7
star
81

ansible-windows-iis

7
star
82

ansible-collection-system

7
star
83

ansible-elk-processors

7
star
84

ansible-bootstrap-python

6
star
85

ansible-postfix

Jinja
6
star
86

ansible-mesosphere

Shell
6
star
87

ansible-influxdb

An Ansible role to install/configure InfluxDB
Jinja
6
star
88

ansible-es-filebeat

6
star
89

ansible-saltstack

An Ansible role to install/configure SaltStack
Jinja
6
star
90

ansible-awx

HTML
6
star
91

vmware-template-scripts

Shell
6
star
92

ansible-postgresql

Enter description of Ansible role
Jinja
6
star
93

ansible-clone-git-repos

Shell
6
star
94

ansible-jenkins

Ruby
6
star
95

ansible-docker-swarm

6
star
96

vagrant-ansible-k8s

Vagrant Ansible lab for Kubernetes
Ruby
6
star
97

ansible-change-hostname

6
star
98

docker-m1-development

Apple M1 development using Docker
Shell
5
star
99

ansible-mariadb-mysql

Shell
5
star
100

ansible-gitlab-runner

5
star