This project aims to build a ALM infrastructure within a virtual environment using Vagrant and provisioning with Ansible.
The picture bellow illustrates the infrastructure defined in the Vagrant file:
The process could be summarized as follows:
-
The main point of interest in this scenario is Jenkins doing his job which is orchestrating a CI/CD process.
-
Next we send the code to be analised by Sonar Source for find some buggy code and to check how good our tests are.
-
For artifact archiving we use Nexus v.3 so our binaries could reside there for later deploy.
-
And finally, a simple machine waiting to receive the binaries and be provisioned by Jenkins using the Ansible Plugin.
I've managed to build a simple lab using this sample workflow that could be found in here. Also, if you are interested, there's a presentation that I did on Ansible Meetup in São Paulo describing this scenario. Enjoy!
-
Tested on Windows 10 20H2
-
Install VirtualBox and Vagrant
-
Use a direct Internet connection before proceeding (stop VPN / connect to "blue" cable for direct Internet access / disconnect from company WiFi and Network if that needs a proxy configuration)
-
Create, start, and provision VMs:
cd jenkins-ansible-vagrant vagrant up
This will ask for the Administrator password (maybe even multiple times).
Vagrant starts the VirtualBox VMs. On the first start it calls Ansible to install and configure the tools/services in the VMs.
- Workaround for
Unable to start service sonarqube
:vagrant ssh sonar # In the sonar VM: sudo chown -R sonar:sonar /opt/sonarqube/ # Back on the host: vagrant provision
- Workaround for
-
Re-run provisioning (in case of errors or subsequent changes):
cd jenkins-ansible-vagrant vagrant rsync vagrant provision
Only re-run provisioning on
ansiblehost
(runs Ansible to provision the other hosts):cd jenkins-ansible-vagrant vagrant rsync ansiblehost vagrant provision ansiblehost
Run Ansible provisioning for only one host type (replace
jenkins_server
with the required host, add-vvv
for debug outputs):cd jenkins-ansible-vagrant vagrant rsync ansiblehost vagrant ssh ansiblehost # In the ansiblehost VM: PYTHONUNBUFFERED=1 ANSIBLE_ROLES_PATH='/home/vagrant/ansible-downloads/roles' \ ansible-playbook \ --inventory-file=/vagrant/ansible/inventory.ini \ /vagrant/ansible/alm.yml \ --limit="jenkins_server"
For speedup, comment-out parts of
alm.yml
, e.g.Update apt
andInstall requirements
. -
SSH Login to VMs, e.g.
jenkins
:vagrant ssh jenkins
-
Optional: Stop
ansiblehost
to save RAM on the Host (that host is only required for provisioning):vagrant halt ansiblehost
-
Open CI Tools in Browser
-
Jenkins: http://172.16.10.100:8080/
Login:
admin
/admin123
-
Nexus: http://172.16.10.120:8081/
Login:
admin
/admin123
-
Sonar: http://172.16.10.110:9000/
Login:
admin
/admin
-
-
Manual configuration steps
- Jenkins:
-
Manage Jenkins -> Global Tool Configuration -> Maven -> Maven installations
Install automatically:
Uncheck
Name:
M3
MAVEN_HOME:
/opt/apache-maven-3.5.4
Save
-
- Jenkins:
-
Example project: soccer-stats
-
Git repository URLs
https://engkaudev001/playground/playgroup-b/jenkins-playground/jenkins-example-projects/soccer-stats
-
Add Jenkins pipeline
TODO
-
Build
TODO
-
View packaged binaries in Nexus
TODO
-
View static code analysis reports in Sonar
TODO
-
Try example project in Browser
TODO
-
-
Stop all VMs of this project:
vagrant halt
-
Delete all VMs of this project:
vagrant destroy
Just install Vagrant on your unix machine and you are ready to go. I've tried to keep the Vagrantfile
as much agnostic as possible to be simple to reproduce on any Vagrant environment. Even if you couldn't manage to work, I hope this file could help you at least as a reference. Also install the Vagrant Networkmanager plugin to have your hosts
file configured accordingly: vagrant plugin install vagrant-hostmanager
.
Remember that the Ansible playbooks on this repo are the real project rock star. It's responsible to give the environment everything you need to build your ALM.
Don't forget to install the Ansible Roles from the repository by executing the following command from the project's root dir:
ansible-galaxy install -r requirements.yml
After your Jenkins server got provisioned, you will need to set:
-
Ansible Tower Global Credentials: a. Username: your username b. Password: your pass c. ID: tower
-
Ansible Tower Installation: a. Name: tower b. URL: https://tower.local c. Credenctials: the same that was set in the last step d. Force Trust Cert: true
-
Maven in Global Tool Configuration: a. Name: M3 b. MAVEN_HOME:
/opt/apache-maven-3.5.4
To provision Ansible Tower you have to first install VirtualBox and then execute: vagrat up tower --provider virtualbox
. A brand new machine with Ansible Tower will be provisioned for you. After installation, go to http://tower.local and set your trial license and you're a set!
The original ansible role geerlingguy.sonar
doesn't work with Postgres. I've already sent a pull request to the original author but until now, he haven't have the time to merge. In the future I have plans to aniquilate the zanini.sonar
role from the local dir and rely only on the Geerling Guy's role.
There's an issue on Vagrant 1.9.1 that is very annoying: the eth01
needs a restart after bring the machine up. Do the following after sshing at the machine:
sudo /etc/init.d/network restart
- Geerling Guy for the awesome roles