How to quickly set up a Centreon 21.04 with Vagrant

Introduction

As published on our blog, we are very happy to share with you the release of the latest Centreon 21.04 version. This is the third time that the Centreon team successfully released a new major version under lockdown mode. 

Before making the release generally available, we needed to test and validate the new version with all its new features and changes. We also asked for help from our community and some members agreed to test the beta packages. We’re grateful for their help! 

In order to speed up the setup of a Centreon environment for testing purposes during the QA phase, we used several solutions such as Docker containers deployed on Portainer, VMs deployed on AWS or VMs locally managed by Vagrant

In this blog post, we will show how to quickly set up Centreon 21.04 with Vagrant.

What is Vagrant?

According to the Vagrant official documentation, Vagrant is a tool for building and managing virtual machine environments in a single workflow

In other words, Vagrant is a tool that allows you to create, configure, and manage virtual machines through a CLI (Command-Line Interface). So this is a layer of software between a virtualization tool (such as VirtualBox, Docker, Hyper-V) and a VM.

Vagrant uses a concept of “boxes” which are the package format for Vagrant environments. And in order to manage these environments, Vagrant uses a Vagrantfile, a standard format for describing an environment. According to the documentation, the primary function of Vagrantfile is to describe the type of machine required for a project, and how to configure and provision these machines. 

Getting started with Vagrant

Prerequisites

Before starting, make sure you already have a virtualization solution on your system. Here we will assume that you already have a working VirtualBox installation, otherwise please follow this documentation.

Installation

In order to install Vagrant, you can follow its official documentation here.  

Set up a project

The simplest way to start a new VM under CentOS 7 for instance (it will generate automatically a Vagrantfile that you can modify later according to your use case).

cd ~ && mkdir vagrant-centos7
cd vagrant-centos7
vagrant init centos/7
vagrant up
vagrant ssh

You are now connected, via SSH, to your newly created CentOS 7 VM!

Provisioning 

You may have noticed that this VM does not come loaded with Centreon 21.04! Fortunately, Vagrant supports automatic provisioning that could be achieved with our unattended.sh script available on our GitHub repository. Don’t worry, we will provide a complete Vagrantfile below 🙂

Some useful commands

You may consult the CLI documentation to get more information. Below some useful commands that will help you to manage your VM.

Command Purpose
vagrant status Get the current status of your box/VM
vagrant halt Stop your current box/VM
vagrant up Start your current box/VM
vagrant reload Stop & restart your current box/VM
vagrant provision Run the provision
vagrant destroy Destroy your current box/VM
vagrant save Snapshot your current box/VM
vagrant restore Restore your box/VM from a snapshot
vagrant ssh Connect via SSH to your box/VM

Set up a Centreon 21.04 central on a CentOS 7 box 

By executing the following instructions, you will be able to initialize a new CentOS 7 VM with a Centreon 21.04 central server.

cd ~ && mkdir vagrant-centreon
cd vagrant-centreon

cat <<EOF > Vagrantfile
#Dynamically generated hostname
HOSTNAME = "centos7." + ENV["USER"] + "." + Time.new.strftime("%Y%m%d.%H%M%S")

#Private IP address
IP = 192.168.150.2
Vagrant.configure("2") do |config|

  # type of the box : CentOS 7 here
  config.vm.box = "centos/7"
  config.vm.network "private_network", ip: "#{IP}"
  config.vm.hostname = "#{HOSTNAME}"

  # allocated resources to the VM
  config.vm.provider "virtualbox" do |vm|
   vm.check_guest_additions = false
   vm.memory = 1024
   vm.cpus = 1
  end

  config.vm.provision "shell",
   path: "https://raw.githubusercontent.com/centreon/centreon/21.04.x/unattended.sh",
   env: {
        "ENV_CENTREON_OPERATION" => "install",
        "ENV_CENTREON_REPO" => "stable",
        "ENV_CENTRAL_IP" => "#{IP}",
        "ENV_CENTREON_TOPOLOGY" => "central",
        "ENV_CENTREON_ADMIN_PASSWD" => "centreon",
        "ENV_MARIADB_CENTREON_PASSWD" => "centreon",
        "ENV_WIZARD_AUTOPLAY" => "true",
        }

end
EOF

vagrant up

A few minutes later, your VM is initialized and you will be able to access to the Centreon web interface at http://192.168.150.2/centreon with these credentials: admin/centreon

One Vagrantfile to rule them all

If you want to manage multiple VMs at once, you call add instructions (for managing a VM) in the same Vagrantfile as below.

ENV["LC_ALL"] = "en_US.UTF-8"

r = Random.new
random_id = r.rand (1..1000)

repos = "stable"

#define your desired environment here
hosts = {
 "poller-1" => { :type => "poller", :ip => "192.168.200.100", :cpus => 1, :mem => 256 },
 "poller-2" => { :type => "poller", :ip => "192.168.200.101", :cpus => 1, :mem => 256 },
 "central" => { :type => "central", :ip => "192.168.200.10", :cpus => 2, :mem => 1024 },
}

os = "oracle8"

Vagrant.configure("2") do |config|
 hosts.each_with_index do |(hostname, info), index|
  config.vm.define hostname do |instance|
     instance_id = "#{os}-#{hostname}-#{random_id}-" + ENV["USER"]

     # type of the box : oracle linux 8 here
     config.vm.box = "oraclelinux/8"
     config.vm.box_url = "https://oracle.github.io/vagrant-projects/boxes/oraclelinux/8.json"

     instance.vm.hostname = "#{instance_id}"
     instance.vm.network "private_network", ip: "#{info[:ip]}"
     instance.vm.provider "virtualbox" do |vm|
       vm.name = "#{instance_id}"
       vm.memory = "#{info[:mem]}"
       vm.cpus = "#{info[:cpus]}"
     end #end of provider

     instance.vm.provision "shell",
     path: "https://raw.githubusercontent.com/centreon/centreon/21.04.x/unattended.sh",
     env: { "ENV_CENTRAL_IP" => "#{info[:ip]}",

            "ENV_CENTREON_TOPOLOGY" => "#{info[:type]}",
            "ENV_CENTREON_OPERATION" => "install",
            "ENV_CENTREON_REPO" => "#{repos}",
            "ENV_CENTREON_ADMIN_PASSWD" => "centreon",
            "ENV_MARIADB_CENTREON_PASSWD" => "centreon",
            "ENV_WIZARD_AUTOPLAY" => "true" }
   end #end of config
 end #end of hosts
end

It will create several VMs that you can use for testing a distributed environment: 

  • 2 Pollers with the latest Centreon 21.04: poller-1 and poller-2
  • 1 Central with the latest Centreon 21.04: central 

You still can use the usual vagrant command to manage each VM individually like:

vagrant status
Current machine states:

poller-1                  running (virtualbox)
poller-2                  running (virtualbox)
central                   running (virtualbox)

This environment represents multiple VMs. The VMs are all listed above with their current state. For more information about a specific VM, run `vagrant status NAME`.

A few words about the environment variables in the Vagrantfile

As you can see, here the provisioning consists of executing the unattended.sh script exactly like you would by following the instructions available on our download.centreon.com website. This script execution will depend on the parameters given in input. In the case of using Vagrant, we can set these parameters as environment variables for the provisioning. 

Variable Purpose Provided value
ENV_CENTREON_OPERATION

Type of operation that will be executed: install or upgrade. 

Currently only the “install” operation from scratch is supported.

install
ENV_CENTREON_TOPOLOGY Type of centreon server that will be installed : a central server or a poller central or poller
ENV_CENTREON_REPO

Centreon yum repositories that will be used for the operation : unstable, testing, stable.

If you want to test beta or unreleased packages, you can set “unstable,testing”.

stable
ENV_CENTRAL_IP IP address of the VM, useful in the case where you want to test with a private network 192.168.150.2 (for instance)
ENV_CENTREON_ADMIN_PASSWD

Centreon default admin user password. 

These credentials will be needed for the Web login.

centreon
ENV_MARIADB_CENTREON_PASSWD

MariaDB default centreon user password. 

These credentials will be used by Centreon for connecting to the MariaDB server.

centreon
ENV_WIZARD_AUTOPLAY If enabled (set to “true) the script will automatically execute the Web installation steps. true

Next step

As you can see,Vagrant allows our team to very quickly initialize a local environment. Indeed, in a few minutes, you can have an environment with a ready-to-use Centreon instance on CentOS 7 or Oracle Linux 8. For your information, for a testing purpose, we also used a RHEL8-box Vagrantfile with an automatic subscription registration mechanism. We are now working on the next step by building official Centreon boxes that we will provide directly on Vagrant Cloud. Please stay tuned!


 

Hung Bui

Hung Bui

Chief Technology Officer, Centreon

Hung Bui is Chief Technology Officer for Centreon, leading the company’s research and development. In this role, Hung oversees technology strategy and product engineering, currently focused on innovations such as AIOps, which combines artificial intelligence, machine learning, analytics and other advanced technologies to improve IT operations. Prior to joining Centreon, Hung held a senior technology role with FastConnect, a cloud computing and performance-led company. Prior to this, he held roles in PKI and digital signature solutions with a variety of software editors. Hung holds a degree in computer science engineering from ESIEE Paris.
Tags :