The aim of the project is to get hands on experience in CI/CD pipeline and on cloud. By the end of the project, we will have a single terraform repository where you can type terraform apply command and it will do CI/CD pipeline for you.
- AWS account
- Amazon Machine Image (AMI) Red Hat Enterprise Linux 8.x
- Terraform required_version = ">= 0.12"
-
Git clone
-
- jenkins-key.pem
- ansible-key.pem
- tomcat-key.pem
4 Provide your private key under Provisioner Connection Settings
-
Provisioner Connection Settings directory of a file
CI-CD-PipelineOnAws/modules/ansible/instance.tf CI-CD-PipelineOnAws/modules/jenkins/instance.tf CI-CD-PipelineOnAws/modules/tomcat/instance.tf connection { type = "ssh" host = self.public_ip user = "ec2-user" private_key = file("~/key/ansible-key.pem") }
-
Specify corrrect PATH for file provisioning to excute bash scripte
-
file provisioning directory of a file
CI-CD-PipelineOnAws/modules/ansible/instance.tf CI-CD-PipelineOnAws/modules/jenkins/instance.tf CI-CD-PipelineOnAws/modules/tomcat/instance.tf provisioner "file" { source = "~/bash-script/ansible.sh" destination = "/tmp/ansible.sh" }
-
-
cd CI-CD-PipelineOnAws/dev
-
Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
$ export AWS_ACCESS_KEY_ID="anaccesskey" $ export AWS_SECRET_ACCESS_KEY="asecretkey"
-
terraform apply
1 Browse http:your-target-ip:8080
2 Username admin
3 Password Location:/var/lib/jenkins/secrets/initialAdminPassword
4 Change password
5 Configure java path
6 Create maven project
7 Configure maven path
8 Provide your project git url
1 Browse http:your-target-ip:8080
2 Allow tomcat to login from browser type #find -name context.xml# 3 context.xml files.
comment () Value ClassName field on files which are under webap directory.
3 Restart tomcat - type tomcatup
4 Copy the following file under /opt/apache-tomcat-8.5.35/conf/tomcat-user.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui, manager-script, manager-jmx, manager-status"/>
<user username="deployer" password="deployer" roles="manager-script"/>
<user username="tomcat" password="root123" roles="manager-gui"/>
5 Restart service and try to login to a tomcat application from the browser use tomcat user with password root123.
1 su - ansadmin
2 ssh-keygen
3 ssh-copy-id target-ip-address (tomcat-ipaddress)
4 nano /etc/ansible/hosts add tomcat ip address
5 test using ansible all -m ping
6 write playbooks under /opt/playbooks