DevOps Project — CI/CD -3

 

In this blog, we are going to build and deploy our application on Docker Container with the help of Ansible.


However, are there any more efficient methods to manage this process?

Yes, that is where we can introduce deployment tool.

sudo su -
useradd ansadmin
passwd ansadmin
vim /etc/ssh/sshd_config
( PasswordAuthentication yes )
visudo
( ansadmin ALL=(ALL) NOPASSWD: ALL )
systemctl restart sshd
sudo su - ansadmin
ssh-keygen
sudo su -
amazon-linux-extras install ansible2 -y
python --version
ansible --version
sudo su -
useradd ansadmin
passwd ansadmin
visudo
( ansadmin ALL=(ALL) NOPASSWD: ALL )
sudo su -
vim /etc/ansible/hosts
[docker]
< docker private ip >
sudo su - ansadmin
ssh-copy-id < docker private ip >
ansible all -m ping

Integration of jenkins with Ansible has been successfull.

sudo su - ansadmin
cd /opt
sudo mkdir docker
sudo chown ansadmin:ansadmin docker
sudo yum install docker -y
sudo usermod -aG docker ansadmin
sudo systemctl enable --now docker
cd /opt/docker
vim Dockerfile
FROM tomcat:latest
RUN cp -R /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps
COPY ./*.war /usr/local/tomcat/webapps
sudo chmod 777 /var/run/docker.sock
sudo vim /etc/ansible/hosts
[docker]
< docker private ip >

[ansible]
< ansible private ip >
ssh-copy-ip < ansible private ip >
sudos u - ansadmin
docker login
cd /opt/docker
vim regapp.yml
---
- hosts: ansible
tasks:
- name: create docker image
command: docker build -t regapp:latest .
args:
chdir: /opt/docker
- name: create tag to push image onto dockerhub
command: docker tag regapp:latest jabirdocker/regapp:latest
- name: push docker image
command: docker push jabirdocker/regapp:latest
ansible-playbook regapp.yml --check
vim deploy_regapp.yml
---
- hosts: docker
tasks:
- name: stop existing container
command: docker stop regapp-server
ignore_errors: yes
- name: remove the container
command: docker rm regapp-server
ignore_errors: yes
- name: remove image
command: docker rmi jabirdocker/regapp:latest
ignore_errors: yes
- name: create container
command: docker run -d --name regapp-server -p 8082:8080 jabirdocker/regapp:latest
ansible-playbook deploy_regapp.yml --check
sudo su -
chmod 777 /var/run/docker.sock
ansible-playbook /opt/docker/regapp.yml;
sleep;
ansible-playbook /opt/docker/deploy_regapp.yml
cd hello-world/webapp/src/main/webapp/
vim index.jsp
git status
git add .
git status
git commit -m "change background colour to blue"
git push origin master

How we can come to know that it is not working out?

How we can create new container automatically?

Comments

Popular posts from this blog

Deploying Zomato Clone App with DevSecOps CI/CD

AUTOMATION MULTIER PROJECT USING VAGRANT