The goal of this lab are to:
- Create a CentOS 7 VM using Vagrant
- Install GitLab on this VM using Ansible
- Perform health checks on the GitLab installation using Ansible
- Vagrant documentation
- Ansible documentation
- Ansible module index
- GitLab installation doc for CentOS 7
- GitLab Health Check doc
Before you can start the lab, you have to:
-
Install Virtualbox: https://www.virtualbox.org/wiki/Downloads
-
Install Vagrant on your computer: https://www.vagrantup.com/downloads.html
-
(Optional) On Windows, ensure that Hyper-V is disabled:
- Open a new Powershell
- Run the following command:
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All
-
Download the
centos/7
Vagrant box for the Virtualbox provider:$ vagrant box add centos/7 ==> box: Loading metadata for box 'centos/7' box: URL: https://vagrantcloud.com/centos/7 This box can work with multiple providers! The providers that it can work with are listed below. Please review the list and choose the provider you will be working with. 1) hyperv 2) libvirt 3) virtualbox 4) vmware_desktop Enter your choice: 3
-
Install vagrant vbguest pluggin (enables folder mounting)
vagrant plugin install vagrant-vbguest
-
Clone the lab repository to your computer:
git clone https://github.com/adaltas/ece-devops.git
-
Go to the
infra-as-code
directory:cd ece-devops/infra-as-code
In the lab, we will use the ansible_local
provisioner, so Ansible will be automatically installed on the VM by Vagrant. You don't need it on your computer!
In the infra-as-code
directory, you will find:
- A
Vagrantfile
that defines the VMs to be managed by Vagrant (1 CentOS 7 VM namedgitlab_server
in our case) - A
playbooks/
directory that contains Ansible playbooks to install GitLab and run health checks
- Take a look at the
Vagrantfile
and at the YAML filesplaybooks/run.yml
andplaybooks/gitlab/install/tasks/main.yml
- Create and provision the VM
- Run the
vagrant up
command - You should end up with the following error (this is planned):
TASK [gitlab/install : Install GitLab] ***************************************** fatal: [gitlab_server]: FAILED! => {"changed": false, "msg": "No package matching 'gitlab-ee' found available, installed or updated", "rc": 126, "results": ["No package matching 'gitlab-ee' found available, installed or updated"]}
- Check that everything is ok by connecting to the VM through SSH:
vagrant ssh gitlab_server
- Run the
- Complete the GitLab installation
- Fill the blanks in
gitlab/install/tasks/main.yml
based on the steps 1. and 2. of the GitLab installation doc for CentOS 7 - Update the playbooks on the VM using
vagrant upload
:vagrant upload playbooks /vagrant/playbooks gitlab_server
- Rerun provisioning with the command
vagrant provision
- Fill the blanks in
- Test your installation by connecting to http://20.20.20.2 (step 3 of the GitLab installation doc):
- Choose a password
- Login as the user
root
using the password
- Read the GitLab Health Check doc
- Run a healthcheck using
curl
:- Connect to the VM using
vagrant ssh
- Run the command:
$ curl http://127.0.0.1/-/health GitLab OK
- Connect to the VM using
- Read
playbooks/roles/gitlab/healthchecks/tasks/main.yml
to understand how it relates - Run the
gitlab/healthcheck
role- Connect to the VM using
vagrant ssh
- Run the playbooks using the right tag (replace
TAG
):ansible-playbook /vagrant/playbooks/run.yml --tags TAG -i /tmp/vagrant-ansible/inventory/vagrant_ansible_local_inventory
- Connect to the VM using
Note: you can also modify the Vagrantfile to change the tag you want to run your playbook with. Then, instead of running the ansible-playbook
command inside the VM (after SSH), you can tell vagrant to run ansible provision again with command:
vagrant provision
- Run the 2 other kind of health checks in the playbook (using the uri module):
- Print the results of the health checks in the console
- (Bonus) Print a custom message with only the disfunctional(s) services in the Readiness check if there are some. To test the printing, stop
redis
using the commandsudo gitlab-ctl stop redis
on the node before running the playbook again. Tip: use thejson
attribute of the response.