From d253f390e02bddc3b588ed9e934ff417e666a110 Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Sun, 20 Sep 2020 15:03:11 -0400 Subject: [PATCH] (WIP) Add Vagrant support --- README.md | 10 +++++++ Vagrantfile | 53 +++++++++++++++++++++++++++++++++++ vagrant/hyperglass-agent.pp | 1 + vagrant/hyperglass-server.pp | 1 + vagrant/provision_basic_el.sh | 40 ++++++++++++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 Vagrantfile create mode 100644 vagrant/hyperglass-agent.pp create mode 100644 vagrant/hyperglass-server.pp create mode 100644 vagrant/provision_basic_el.sh diff --git a/README.md b/README.md index 3d87de1..34ba36d 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,16 @@ Please take a look at the official It explains the three different options very well. You can pass the hashes from the documentation 1:1 to the tree parameters. +### Beginning with Hyperglass + +This module provides Vagrant definitions that can be used to get started +with Hyperglass. The following will produce VM's for a Hyperglass server +and an agent. + +```bash +vagrant up +``` + ## Tests This module has several unit tests and linters configured. You can execute them diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..ac05220 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,53 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : +# +# Environment variables may be used to control the behavior of the Vagrant VM's +# defined in this file. This is intended as a special-purpose affordance and +# should not be necessary in normal situations. If there is a need to run +# multiple backend instances simultaneously, avoid the IP conflict by setting +# the ALTERNATE_IP environment variable: +# +# ALTERNATE_IP=192.168.52.9 vagrant up sensu-backend +# +# NOTE: The agent VM instances assume the backend VM is accessible on the +# default IP address, therefore using an ALTERNATE_IP is not expected to behave +# well with agent instances. +if not Vagrant.has_plugin?('vagrant-vbguest') + abort <<-EOM + +vagrant plugin vagrant-vbguest >= 0.16.0 is required. +https://github.com/dotless-de/vagrant-vbguest +To install the plugin, please run, 'vagrant plugin install vagrant-vbguest'. + + EOM +end + +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +VAGRANTFILE_API_VERSION = "2" + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + + config.vm.synced_folder ".", "/vagrant", type: "virtualbox" + + config.vm.provider :virtualbox do |vb| + vb.customize ["modifyvm", :id, "--memory", "512"] + end + + config.vm.define "hyperglass-server", primary: true, autostart: true do |c| + c.vm.box = "centos/7" + c.vm.hostname = 'hyperglass-server.example.com' + c.vm.network :private_network, ip: ENV['ALTERNATE_IP'] || '192.168.73.10' + c.vm.network :forwarded_port, guest: 8001, host: 8001, auto_correct: true + c.vm.provision :shell, :path => "vagrant/provision_basic_el.sh" + c.vm.provision :shell, :inline => "puppet apply /vagrant/vagrant/hyperglass-server.pp" + end + + config.vm.define "el7-agent", primary: true, autostart: true do |c| + c.vm.box = "centos/7" + c.vm.hostname = 'el7-agent.example.com' + c.vm.network :private_network, ip: ENV['ALTERNATE_IP'] || '192.168.73.20' + c.vm.network :forwarded_port, guest: 8443, host: 8443, auto_correct: true + c.vm.provision :shell, :path => "vagrant/provision_basic_el.sh" + c.vm.provision :shell, :inline => "puppet apply /vagrant/vagrant/hyperglass-agent.pp" + end +end diff --git a/vagrant/hyperglass-agent.pp b/vagrant/hyperglass-agent.pp new file mode 100644 index 0000000..f43bcba --- /dev/null +++ b/vagrant/hyperglass-agent.pp @@ -0,0 +1 @@ +include hyperglass::agent diff --git a/vagrant/hyperglass-server.pp b/vagrant/hyperglass-server.pp new file mode 100644 index 0000000..715b13c --- /dev/null +++ b/vagrant/hyperglass-server.pp @@ -0,0 +1 @@ +include hyperglass::server diff --git a/vagrant/provision_basic_el.sh b/vagrant/provision_basic_el.sh new file mode 100644 index 0000000..6497b4d --- /dev/null +++ b/vagrant/provision_basic_el.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# using this instead of "rpm -Uvh" to resolve dependencies +function rpm_install() { + package=$(echo $1 | awk -F "/" '{print $NF}') + wget --quiet $1 + yum install -y ./$package + rm -f $package +} + +release=$(awk -F \: '{print $5}' /etc/system-release-cpe) + +rpm --import http://download-ib01.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-${release} +rpm --import http://yum.puppetlabs.com/RPM-GPG-KEY-puppet +rpm --import http://vault.centos.org/RPM-GPG-KEY-CentOS-${release} + +yum install -y wget + +# install and configure puppet +rpm -qa | grep -q puppet +if [ $? -ne 0 ] +then + + rpm_install http://yum.puppetlabs.com/puppet5-release-el-${release}.noarch.rpm + yum -y install puppet-agent + ln -s /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet +fi + +# use local hyperglass module +puppet resource file /etc/puppetlabs/code/environments/production/modules/hyperglass ensure=link target=/vagrant + +# setup module dependencies +puppet module install puppetlabs/stdlib --version ">= 6.4.0 < 7.0.0" +puppet module install camptocamp/systemd --version ">= 2.10.0 < 3.0.0" +puppet module install puppet/redis --version ">= 6.1.0 < 7.0.0" +puppet module install puppet/nginx --version ">= 2.0.0 < 3.0.0" +puppet module install puppet/nodejs --version ">= 8.0.0 < 9.0.0" +puppet module install puppet/python --version ">= 4.1.1 < 5.0.0" + +puppet resource host sensu-backend.example.com ensure=present ip=192.168.73.10 host_aliases=hyperglass-server