Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Jenkins Deployement #280

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Jenkins_Build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Provisiong EC2 Instance in AWS and Jenkins Deployment into Remote Server

## Pre-Requisites

- Requires Ansible 1.2 or newer
- Expects CentOS/RHEL 6 or 7 hosts
- python boto installation

## Install Boto using following Command

pip install boto

## Provisioning EC2 Instance

To Deploy EC2 instance, edit the `group_vars/all` file to set any EC2 configuration parameters you need & use `aws_ec2_launch.yml`.

Deploy EC2 instance using below command:

ansible-playbook aws_ec2_launch.yml

## Jenkins Server Deployement


To Deploy Jenkins server using `site.yml`, first edit `hosts` file by adding remote ip's on which jenkins should be installed.

Deploy Jenkins server on to remote IP with username and password into using below command:

ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook site.yml -i hosts --extra-vars 'ansible_ssh_pass=YOUR-SSH-PASSWORD-HERE ansible_ssh_user=YOUR-SSH-USERNAME-HERE'

Deploy Jenkins server onto remote IP with .pem file using below command:

ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook site.yml -i hosts --private-key /mnt/test/cginnovpoc.pem

Deploy Jenkins server standalone using below command:

ansible-playbook site.yml

When the playbook run completes, you should be able to see the Jenkins Server running on the port 8080.
Eg: localhost:8080

24 changes: 24 additions & 0 deletions Jenkins_Build/aws_ec2_launch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: ec2
hosts: localhost
connection: local
vars_files:
- group_vars/all
#gather_facts: False
#i- hosts: localhost
tasks:
- name: launching AWS instance using Ansible
ec2:
key_name: "{{ ec2_key_name }}"
instance_type: "{{ ec2_instance_type }}"
image: "{{ ec2_image }}"
region: "{{ ec2_region }}"
wait: yes
group_id: "{{ ec2_group_id }}"
count: "{{ ec2_instance_count }}"
vpc_subnet_id: "{{ ec2_vpc_subnet_id }}"
assign_public_ip: yes
aws_access_key: "{{ ec2_access_key }}"
aws_secret_key: "{{ ec2_secret_key }}"
instance_tags:
Name: "{{ ec2_instance_name }}"
13 changes: 13 additions & 0 deletions Jenkins_Build/group_vars/all
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# AWS specific variables
ec2_access_key:
ec2_secret_key:
ec2_region: eu-west-1
ec2_image: ami-04facb3ed127a2eb6
ec2_instance_type: t2.micro
ec2_instance_count: 1
ec2_key_name:
ec2_group_id:
ec2_vpc_subnet_id:
ec2_instance_name: jenkins-instance
ec2_tag: demo
#wait_for_port: 22
1 change: 1 addition & 0 deletions Jenkins_Build/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
2 changes: 2 additions & 0 deletions Jenkins_Build/roles/jenkins/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for jenkins
2 changes: 2 additions & 0 deletions Jenkins_Build/roles/jenkins/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for jenkins
53 changes: 53 additions & 0 deletions Jenkins_Build/roles/jenkins/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.9

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

26 changes: 26 additions & 0 deletions Jenkins_Build/roles/jenkins/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Wait for connection
wait_for_connection:
delay: 10
timeout: 600
- name: Install Java 1.8 and some basic dependencies
yum:
name: ['wget', 'zip', 'java-1.8.0-openjdk', 'firewalld']
state: present
- name: Download jenkins.repo
get_url:
url: http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
dest: /etc/yum.repos.d/jenkins.repo
- name: Import Jenkins Key
rpm_key:
state: present
key: https://jenkins-ci.org/redhat/jenkins-ci.org.key
- name: Install Jenkins
yum:
name: jenkins
state: present
- name: Start & Enable Jenkins
systemd:
name: jenkins
state: started
enabled: true
2 changes: 2 additions & 0 deletions Jenkins_Build/roles/jenkins/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions Jenkins_Build/roles/jenkins/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- jenkins
4 changes: 4 additions & 0 deletions Jenkins_Build/roles/jenkins/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
# vars file for apache
ansible_user: "ec2-user"
ansible_port: "22"
7 changes: 7 additions & 0 deletions Jenkins_Build/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: install jenkins
hosts: all
become: yes
roles:
- jenkins