diff --git a/Jenkins_Build/README.md b/Jenkins_Build/README.md new file mode 100644 index 000000000..5b2e91d59 --- /dev/null +++ b/Jenkins_Build/README.md @@ -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 + diff --git a/Jenkins_Build/aws_ec2_launch.yml b/Jenkins_Build/aws_ec2_launch.yml new file mode 100644 index 000000000..297b251dc --- /dev/null +++ b/Jenkins_Build/aws_ec2_launch.yml @@ -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 }}" diff --git a/Jenkins_Build/group_vars/all b/Jenkins_Build/group_vars/all new file mode 100644 index 000000000..54fbab1d6 --- /dev/null +++ b/Jenkins_Build/group_vars/all @@ -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 diff --git a/Jenkins_Build/hosts b/Jenkins_Build/hosts new file mode 100644 index 000000000..2fbb50c4a --- /dev/null +++ b/Jenkins_Build/hosts @@ -0,0 +1 @@ +localhost diff --git a/Jenkins_Build/roles/jenkins/defaults/main.yml b/Jenkins_Build/roles/jenkins/defaults/main.yml new file mode 100644 index 000000000..e848bd6a2 --- /dev/null +++ b/Jenkins_Build/roles/jenkins/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for jenkins \ No newline at end of file diff --git a/Jenkins_Build/roles/jenkins/handlers/main.yml b/Jenkins_Build/roles/jenkins/handlers/main.yml new file mode 100644 index 000000000..e4060b4c1 --- /dev/null +++ b/Jenkins_Build/roles/jenkins/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for jenkins \ No newline at end of file diff --git a/Jenkins_Build/roles/jenkins/meta/main.yml b/Jenkins_Build/roles/jenkins/meta/main.yml new file mode 100644 index 000000000..227ad9c34 --- /dev/null +++ b/Jenkins_Build/roles/jenkins/meta/main.yml @@ -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. + \ No newline at end of file diff --git a/Jenkins_Build/roles/jenkins/tasks/main.yml b/Jenkins_Build/roles/jenkins/tasks/main.yml new file mode 100644 index 000000000..fa5b2471b --- /dev/null +++ b/Jenkins_Build/roles/jenkins/tasks/main.yml @@ -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 diff --git a/Jenkins_Build/roles/jenkins/tests/inventory b/Jenkins_Build/roles/jenkins/tests/inventory new file mode 100644 index 000000000..878877b07 --- /dev/null +++ b/Jenkins_Build/roles/jenkins/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/Jenkins_Build/roles/jenkins/tests/test.yml b/Jenkins_Build/roles/jenkins/tests/test.yml new file mode 100644 index 000000000..846c4ff17 --- /dev/null +++ b/Jenkins_Build/roles/jenkins/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - jenkins \ No newline at end of file diff --git a/Jenkins_Build/roles/jenkins/vars/main.yml b/Jenkins_Build/roles/jenkins/vars/main.yml new file mode 100644 index 000000000..1a68d6d7f --- /dev/null +++ b/Jenkins_Build/roles/jenkins/vars/main.yml @@ -0,0 +1,4 @@ +--- +# vars file for apache +ansible_user: "ec2-user" +ansible_port: "22" diff --git a/Jenkins_Build/site.yml b/Jenkins_Build/site.yml new file mode 100644 index 000000000..9eaa6e259 --- /dev/null +++ b/Jenkins_Build/site.yml @@ -0,0 +1,7 @@ +--- +- name: install jenkins + hosts: all + become: yes + roles: + - jenkins +