Today I want to show you a CI/CD automation of Jenkins through Ansible. This is a fully Automated system from just after uploading the code to GitHub to ready the web-server but behind the scene, there is a lot of things. I want to show you all the process which I do to set up this Automated system.
You Know about GitHub, Jenkins, Docker as I talk about this so many times. But, what is Ansible ?
Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration. Ansible was written by Michael DeHaan and acquired by Red Hat in 2015. Ansible is agentless, temporarily connecting remotely via SSH or Windows Remote Management to do its tasks. For more info you can take reference from here
Ansible is Simple IT Automation
Ansible is the simplest way to automate apps and IT infrastructure. Application Deployment + Configuration Management +…
There are two ways in Ansible to write the code.
- Ansible ad-hoc command: An ansible ad-hoc command is a one-line command that lets you perform basic tasks efficiently without writing playbooks. An Ansible ad-hoc command uses ansible command-line tool to automate a single task on one or more managed nodes. Ad-hoc commands are quick and easy, but they are not reusable. Ad-hoc commands demonstrate the simplicity and power of Ansible. To know more about this, you can click here.
Introduction to ad-hoc commands - Ansible Documentation
An Ansible ad-hoc command uses the /usr/bin/ansible command-line tool to automate a single task on one or more managed…
- Ansible-Playbooks: Playbooks are nothing but files consisting of your written code, and they are written in YAML format, which defines the tasks and executes them through the Ansible. Playbooks may include one or more plays. Plays defines a set of activities or tasks to be run on hosts of inventory file. To know more about this, you can click here.
Intro to Playbooks - Ansible Documentation
Playbooks are a completely different way to use ansible than in ad-hoc task execution mode, and are particularly…
In this demonstration I am using Ansible-playbook as because we need to do lots of activities.
As developer push the code on GitHub so it Automatically set up our own web- server ready and test it also.
- Download the Ansible
- First, configure the Ansible. After that run the Jenkins job.
- Job 1: As Developer upload the code on GitHub so Jenkins download that code automatically.
- Job 2: Setup up our environment ready.
- Job 3: Check our web-server is working good or not. If not mail to the developer.
For downloading the Ansible there is two such ways available:
First one through pip
pip3 install ansible
Second one through package manager
(“Recommend way if you want to do same setup as mine”)
In my case, I do my setup on the top of RedHat so the command is:
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpmyum install ansible -y
Here, I put this is recommended way as because when you install anything from package manager so it downloads to all users. But if you download from python library so it’s only downloaded in root user.
After download you need to configure the ansible. For configuring you need to create a file anywhere like I create in /etc/myhost.txt and write information about your managed nodes.
Now you need to tell ansible about this file. For this go to /etc/ansible and create a file name ansible.conf . Here, you tell about ansible for this file.
Now your setup is ready for working. Just for Checking you can run command
Now Create a Pipeline of Jenkins for configuring our web-server.
As developer put the code on GitHub. So automatically job 1 triggers through web-hooks. I also give one more option of trigger build remotely so developer also run job 1 remotely after upload the code on GitHub .
Now, you need to set up your web-server ready.
This is the main step for this whole set up. As because our main desire is to just launch our web-server. How and where that’s not matter.
This is testing job.
As they also check our site is working perfectly or not. If not so mail to the developer.
Now, I am create a build pipeline for view so I can view this beautifully.
If you also see this green signal. That means your server is ready for you. You can also see this manually.
GitHub link which I used in this task
Thank you for reading …
Connect with me On Linkedin For FurThur Queries Or Suggestion’s if u Have Any !!!