Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

Latest commit

 

History

History
212 lines (143 loc) · 5.54 KB

google-cloud.md

File metadata and controls

212 lines (143 loc) · 5.54 KB

Deploy Centreon with Ansible and Google Cloud Compute

Table of Contents

Overview

This tutorial is intended to guide and exemplify the use of the Ansible tool to deploy a Centreon environment in Google cloud service.

The idea is to show how easy it is to implement and automate the entire creation and maintenance process of Centreon in a cloud, from instance creation to configuration.

Requirements

To use automation with Google Cloud, we first need to perform some tasks in the admin panel on Google, to do this, you will need to create the credentials.

It’s easy to create a GCP account with credentials for Ansible. You have multiple options to get your credentials - here are two of the most common options:

  • Service Accounts (Recommended): Use JSON service accounts with specific permissions.
  • Machine Accounts: Use the permissions associated with the GCP Instance you’re using Ansible on.

For the following examples, we’ll be using service account credentials.

To work with the GCP modules, you’ll first need to get some credentials in the JSON format:

  1. Create a Service Account
  2. Download JSON credentials

See more in this link.

Installation

Using Ubuntu Linux

If you already have a system ready to use Ansible, skip to the Ansible installation step.

With Vagrant

Create a new environment

mkdir ubuntu-ansible
cd ubuntu-ansible
vagrant init ubuntu/bionic64
vagrant up
vagrant ssh

Add basic tools

sudo apt update
sudo apt install -y curl less neovim dialog libterm-readline-gnu-perl

With Docker

Create a new environment

docker run -it --hostname ubuntu-ansible ubuntu:latest

Add basic tools

apt update
apt install -y sudo curl less neovim dialog libterm-readline-gnu-perl

Using Centos/Redhat Linux

If you already have a system ready to use Ansible, skip to the Ansible installation step.

With Vagrant

Create a new environment

mkdir centos-ansible
cd centos-ansible
vagrant init centos/7
vagrant up
vagrant ssh

Add basic tools

sudo yum upgrade -y
sudo yum install -y epel-release
sudo yum install -y curl less git

With Docker

Create a new environment

docker run -it --hostname centos-ansible centos:7

Add basic tools

yum upgrade -y
yum install -y epel-release
yum install -y sudo curl less git

Installation of Ansible

It is recommended that you always use the latest stable version of Ansible. The project supports a wide range of operating systems. You can see more information at this link.

Ubuntu

sudo apt-get update
sudo apt-get install -y software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt-get install -y ansible

Centos/Redhat

sudo yum install -y ansible

You will need some libraries to support Google Cloud Compute

Ubuntu

sudo apt install -y python-google-auth python-requests python-libcloud

Centos/Redhat

sudo yum install -y python-requests python2-libcloud

Centreon Deploy

Now prepare the environment with the Ansible module for the deploy of the Centreon, for this, we will use the repository of the implementation module of Centreon through Git.

git clone https://github.com/centreon/centreon-iac-ansible.git
cd centreon-iac-ansible

You will now need to prepare your deploy yaml file and the access key provided by Google in json format, as per the instructions in this site.

Here, I'm going to use the sample deploy file provided in the Centreon module repository:

cp docs/examples/gc-centreon.yml .

Edit the file gc-centreon.yml with your values from Google Compute:

  vars:
    service_account_email: XXXXXXXXX-compute@developer.gserviceaccount.com
    credentials_file: centreon-XXXXXXXXX.json
    project_id: centreon-XXXXXXX
    machine_type: f1-micro
    image: centos-7

Set the machine_type according to your needs and save the file.

Now you will need to create or use your public ssh key to use in Google Compute instances, if you do not already have it, use the command below to create and get the public key

SSH keygen

Tip

To avoid stops with key issues in ssh, add this line in the configuration file of your ssh

cat <<EOF >> ~/.ssh/config
Host *
    StrictHostKeyChecking no
EOF
chmod 0600 ~/.ssh/config

Use the public key in the new instances by adding in the block on the file gc-centreon.yml

metadata: '{"ssh-keys":"admin: ... add your public ssh key here ... "}'

With this and with your proper settings of deploy of the Centreon, just run the deploy command of Ansible

ansible-playbook gc-centreon.yml

Screencast

You can follow here a complete screencast of deploy in Google Compute Centreon Ansible with Google