DEV Community

Prabhat Singh
Prabhat Singh

Posted on

GitLab CD Pipeline for Linux package management

Good Day Everyone!

Hope you’re all doing well.

I’m writing this article to share my learnings while working on different projects involving multiple skills in Telecommunications and Information Technology domains.

Recent project has enabled me with the skills such as GitLab, Ansible, Docker, and Shell script.

Use case

Package management on multiple Linux machines using GitLab pipeline

Tools

Following DevOps tools were used in implementing the CD pipeline

  • GitLab — Version control, project repository, CD pipeline

  • GitLab-Runner — Trigger the pipeline stages

  • Linux Machines — Centos VMs for controller node and target nodes

  • Ansible — Implements changes on the target nodes

  • Shell Scripting — Execute playbooks, used in the pipeline stages

Architecture

Below is a high level architecture of the setup

Architecture

Prerequisites

  • GitLab account where you can store your project and configure CD pipeline.

  • Gitlab-runner package downloaded and installed on the controller node, which is basically a Linux machine.

Gitlab-runner

  • Gitlab-runner for the project has been registered on the controller node. Navigate to GitLab → Project → Settings → CI/CD → Runners. Scroll down to the steps where it shows the steps to register gitlab-runner on the controller node.

register-process

  • Register the runner on the controller node with the details mentioned above. For this exercise, shell executor for gitlab-runner is used to trigger the gitlab jobs on the target machines.

register-runner

  • Ansible installed on the controller node. For testing purpose, inventory file consists of the entry for the localhost
targetvm1 ansible_host=127.0.0.1 ansible_user=root
Enter fullscreen mode Exit fullscreen mode

ansible

ssh-connection

  • Git is installed on your local machine to clone, pull, & push the changes in your local repository

git

Implementation

  • Clone the project from the Github on your local machine

github

  • Change to the directory and edit the variables.yml and provide values against the parameters mentioned

variables

  • Commit the changes to your local repository and push to the remote repository

commit-change

push-change

  • As soon as you push the changes, a pipeline will be triggered on GitLab. Navigate to GitLab → Project → CI/CD → Pipelines.

  • Stages include in the pipeline: prechecks, prebackup, activity, postbackup, postchecks.

pipeline-stages

pipeline-status

Ansible playbooks can further be modified for different operating systems, system checks, system backup before and after the installation, upgrade, & removal of the packages.

Discussion (0)