Skip to content
EgyKode
05 · Configuration managementLab 31 / 59
Guided labansible

Automated Jenkins Server & Toolchain Provisioning

Structure 8 modular Ansible roles under roles/.

Time
31 min
Level
Intermediate
Objectives
4 objectives
Cost
Low cost

Where this fits in the platform

Before you start

CostLow cost

— one `t3.micro` for Jenkins. Note that Jenkins wants more memory than a micro provides for real builds; a `t3.small` is ~$15/month.

Nothing to pay in the browser. Open the terminal runs this against a simulated cloud — the same API calls and the same commands, with no account and no bill. The figure above applies only if you build it in your own.

How to clean up

The scenario#

Setting up the build server is a wiki page with nineteen steps. It was last accurate in March. The person who wrote it has left, and the server is one disk failure from being unbuildable.

Hands-on environment

Run this lab in a real terminal, free and in your browser. The environment is temporary and yours alone — break it as much as you like.

Open the terminal

Opens in Killercoda, in a new tab — keep this page open for the steps.

Run it on your own machine

Run this lab on your own machine. One command starts the environment, with everything the lab needs already installed:

The lab text targets an EC2 instance. Locally the same playbook targets the node1 container instead — the inventory changes, the roles and handlers do not.

You will need:

  • ansible
git clone https://github.com/EgyKode/EgyKode-lab.git
cd EgyKode-lab
./egykode start
./egykode shell
ssh node1

You need Docker and Git installed. Everything else runs inside the environment. The first start downloads it and takes a few minutes; later starts are seconds.

Not sure what you already have? Run: npm run doctor — it checks and changes nothing.

Run it on AWS

This lab builds real cloud infrastructure, so it needs your own AWS account. Follow the cost and cleanup notes above — the resources are yours, and so is the bill.

Anything you tick here is your own record. EgyKode cannot see inside that terminal, so the success criteria stay self-assessed even when the environment checks your work for you.

The composition

Step 1 of 4

What you are building#

A role per concern, composed by one playbook:

text
  playbooks/site.yml
      |
      +-- common      packages, timezone, users, hardening
      +-- java        OpenJDK 21 (Jenkins refuses to start on 17)
      +-- docker      engine, the jenkins user in the docker group
      +-- jenkins     repository, package, plugins, service
      +-- aws_cli     v2 from the official installer
      +-- kubectl     pinned to the cluster's minor version
      +-- helm        via the official script
      +-- trivy       scanner used by the pipeline
      +-- sonarqube   quality gate, in a container

A role is a directory layout Ansible understands. Putting a file in roles/java/tasks/main.yml is the wiring — there is no registration step. The alternative is one 1,000-line playbook where nothing can be reused and any change risks everything.


Build it#

Verify it worked#

Terminal
ansible-playbook playbooks/site.yml
# PLAY RECAP: changed=23
 
ansible-playbook playbooks/site.yml
# PLAY RECAP: changed=0          <- the point of the whole lab
 
ansible-playbook playbooks/verify.yml
ansible-playbook playbooks/site.yml --check --diff       # what would change
ansible-playbook playbooks/site.yml --tags jenkins       # one role only

changed=0 on the second run is the definition of idempotent, and it is what lets this playbook run on a schedule to correct drift rather than being a one-shot installer.


Clean up#

Terminal
# Nothing to destroy here — the instance belongs to the Terraform lab.
ansible -m command -a "systemctl status jenkins --no-pager" tag_Role_jenkins

Cost of this lab: Low. You pay for the instance being configured, not for Ansible.

Success criteria

0 of 4

The concept behind it

Ready to try it without help?Do the challenge

Phase complete · 05 Configuration management

You can now: A new server is provisioned and configured with no manual steps, and a second run changes nothing.

Next phase

Lab 31 of 59 on the project path

06 · KubernetesKubernetes Workloads: Pod, ReplicaSet, DeploymentWatch a Deployment create a ReplicaSet create Pods, then delete each in turn and see which come back.45 minBeginner

Previous: Ansible Roles, Variables & Idempotency