Skip to content

Instantly share code, notes, and snippets.

View ernesen's full-sized avatar

Ernese Norelus ernesen

  • Synpulse
View GitHub Profile
provider "aws" {
region = "${var.region}"
profile = "${var.profile}"
}
resource "aws_key_pair" "demo_key" {
key_name = "MyKeyPair"
public_key = "${file(var.public_key)}"
}
/*
resource "aws_vpc" "my-vpc" {
cidr_block = "10.0.0.0/16" # Defines overall VPC address space
enable_dns_hostnames = true # Enable DNS hostnames for this VPC
enable_dns_support = true # Enable DNS resolving support for this VPC
output "url-jenkins" {
value = "http://${aws_instance.jenkins-ci.0.public_ip}:8080"
}
output "url-gitLab" {
value = "http://${aws_instance.gitLab.0.public_ip}"
}
terraform {
required_version = ">= 0.11.11"
}
variable "profile" {
default = "terraform_iam_user"
}
variable "region" {
default = "ap-southeast-1"
}
variable "instance" {
default = "t2.nano"
---
- name: Install Oracle Java version 8
hosts: java
become: true
tasks:
- name: Install dependencies
become: yes
apt:
name: "{{ packages }}"
---
- name: Install Jenkins
hosts: jenkins-ci
gather_facts: false
become: true
tasks:
- name: Ensure the jenkins apt repository key is installed
apt_key:
url: https://pkg.jenkins.io/debian-stable/jenkins.io.key
---
- name: Install GitLab
hosts: gitLab
become: true
tasks:
- name: Checking to make sure postfix is installed
apt:
name:
- postfix
# Ansible requires Python to be installed on the remote machine as well as the local machine.
provisioner "remote-exec" {
inline = ["sudo apt-get -qq install python -y"]
}
connection {
private_key = "${file(var.private_key)}"
user = "ubuntu"
}
# This is where we configure the instance with ansible-playbook
# Jenkins requires Java to be installed
provisioner "local-exec" {
command = <<EOT
sleep 30;
>java.ini;
echo "[java]" | tee -a java.ini;
echo "${aws_instance.jenkins-ci.public_ip} ansible_user=${var.ansible_user} ansible_ssh_private_key_file=${var.private_key}" | tee -a java.ini;
export ANSIBLE_HOST_KEY_CHECKING=False;
ansible-playbook -u ${var.ansible_user} --private-key ${var.private_key} -i java.ini ../playbooks/install_java.yaml