diff --git a/host b/host new file mode 100644 index 0000000..366b0a4 --- /dev/null +++ b/host @@ -0,0 +1,14 @@ +[jenkins-master] +10.1.1.78 + +[jenkins-master:vars] +ansible_user=ubuntu +ansible_ssh_private_key_file=/opt/dppa.pem + +[jenkins-slave] +10.1.1.18 + +[jenkins-slave:vars] +ansible_user=ubuntu +ansible_ssh_private_key_file=/opt/dppa.pem + diff --git a/jenkins-master-setup.yaml b/jenkins-master-setup.yaml new file mode 100644 index 0000000..ab97f51 --- /dev/null +++ b/jenkins-master-setup.yaml @@ -0,0 +1,34 @@ +--- +- host: jenkins-master + become: true + tasks: + - name: add jenkins key + apt_key: + url: https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key + state: present + +- name: add jenkins repo + apt_repository: + repo: 'deb https://pkg.jenkins.io/debian-stable binary/' + state: present + +- name: install java + apt: + name: openjdk-17-jre + state: present + +- name: install jenkins + apt: + name: jenkins + state: present + +- name: start jenkins service + service: + name: + state: started + +- name: enable jenkins to start at boot time + service: + name: jenkins + enable: yes + diff --git a/terraform_code/V1-EC2.tf b/terraform_code/V1-EC2.tf deleted file mode 100644 index 891975d..0000000 --- a/terraform_code/V1-EC2.tf +++ /dev/null @@ -1,9 +0,0 @@ -provider "aws" { - region = "us-east-1" -} - -resource "aws_instance" "demo-server" { - ami = "ami-022e1a32d3f742bd8" - instance_type = "t2.micro" - key_name = "dpp" -} \ No newline at end of file diff --git a/terraform_code/V2-EC2.tf b/terraform_code/V2-EC2.tf deleted file mode 100644 index 2c2cf52..0000000 --- a/terraform_code/V2-EC2.tf +++ /dev/null @@ -1,36 +0,0 @@ -provider "aws" { - region = "us-east-1" -} - -resource "aws_instance" "demo-server" { - ami = "ami-022e1a32d3f742bd8" - instance_type = "t2.micro" - key_name = "dpp" - security_groups = [ "demo-sg" ] -} - -resource "aws_security_group" "demo-sg" { - name = "demo-sg" - description = "SSH Access" - - ingress { - description = "Shh access" - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } - - egress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - ipv6_cidr_blocks = ["::/0"] - } - - tags = { - Name = "ssh-prot" - - } -} \ No newline at end of file diff --git a/terraform_code/V3-EC2-With_VPC.tf b/terraform_code/V3-EC2-With_VPC.tf deleted file mode 100644 index 4bb5512..0000000 --- a/terraform_code/V3-EC2-With_VPC.tf +++ /dev/null @@ -1,93 +0,0 @@ -provider "aws" { - region = "us-east-1" -} - -resource "aws_instance" "demo-server" { - ami = "ami-053b0d53c279acc90" - instance_type = "t2.micro" - key_name = "dpp" - //security_groups = [ "demo-sg" ] - vpc_security_group_ids = [aws_security_group.demo-sg.id] - subnet_id = aws_subnet.dpp-public-subnet-01.id - -} - -resource "aws_security_group" "demo-sg" { - name = "demo-sg" - description = "SSH Access" - vpc_id = aws_vpc.dpp-vpc.id - - ingress { - description = "Shh access" - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } - - egress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - ipv6_cidr_blocks = ["::/0"] - } - - tags = { - Name = "ssh-prot" - - } -} - -resource "aws_vpc" "dpp-vpc" { - cidr_block = "10.1.0.0/16" - tags = { - Name = "dpp-vpc" - } - -} - -resource "aws_subnet" "dpp-public-subnet-01" { - vpc_id = aws_vpc.dpp-vpc.id - cidr_block = "10.1.1.0/24" - map_public_ip_on_launch = "true" - availability_zone = "us-east-1a" - tags = { - Name = "dpp-public-subent-01" - } -} - -resource "aws_subnet" "dpp-public-subnet-02" { - vpc_id = aws_vpc.dpp-vpc.id - cidr_block = "10.1.2.0/24" - map_public_ip_on_launch = "true" - availability_zone = "us-east-1b" - tags = { - Name = "dpp-public-subent-02" - } -} - -resource "aws_internet_gateway" "dpp-igw" { - vpc_id = aws_vpc.dpp-vpc.id - tags = { - Name = "dpp-igw" - } -} - -resource "aws_route_table" "dpp-public-rt" { - vpc_id = aws_vpc.dpp-vpc.id - route { - cidr_block = "0.0.0.0/0" - gateway_id = aws_internet_gateway.dpp-igw.id - } -} - -resource "aws_route_table_association" "dpp-rta-public-subnet-01" { - subnet_id = aws_subnet.dpp-public-subnet-01.id - route_table_id = aws_route_table.dpp-public-rt.id -} - -resource "aws_route_table_association" "dpp-rta-public-subnet-02" { - subnet_id = aws_subnet.dpp-public-subnet-02.id - route_table_id = aws_route_table.dpp-public-rt.id -} \ No newline at end of file diff --git a/terraform_code/V4-EC2-With_VPC_for_each.tf b/terraform_code/V4-EC2-With_VPC_for_each.tf index 0fcbe6e..5798384 100644 --- a/terraform_code/V4-EC2-With_VPC_for_each.tf +++ b/terraform_code/V4-EC2-With_VPC_for_each.tf @@ -3,32 +3,34 @@ provider "aws" { } resource "aws_instance" "demo-server" { - ami = "ami-053b0d53c279acc90" - instance_type = "t2.micro" - key_name = "dpp" - //security_groups = [ "demo-sg" ] - vpc_security_group_ids = [aws_security_group.demo-sg.id] - subnet_id = aws_subnet.dpp-public-subnet-01.id -for_each = toset(["jenkins-master", "build-slave", "ansible"]) - tags = { - Name = "${each.key}" - } -} + ami = "ami-0c7217cdde317cfec" + instance_type = "t2.micro" + + key_name = "dppa" + //security_groups = [ "demo-sg" ] + vpc_security_group_ids = [aws_security_group.demo-sg.id] + subnet_id = aws_subnet.dppa-public_subent_01.id + + for_each = toset(["jenkins-master", "build-slave", "ansible"]) + tags = { + Name = "${each.key}" + } +} resource "aws_security_group" "demo-sg" { name = "demo-sg" description = "SSH Access" - vpc_id = aws_vpc.dpp-vpc.id - + vpc_id = aws_vpc.dppa-vpc.id + ingress { - description = "SHH access" - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } + description = "ssh access" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } - ingress { + ingress { description = "Jenkins port" from_port = 8080 to_port = 8080 @@ -45,60 +47,62 @@ resource "aws_security_group" "demo-sg" { } tags = { - Name = "ssh-prot" - + Name = "ssh-port" } } -resource "aws_vpc" "dpp-vpc" { +resource "aws_vpc" "dppa-vpc" { cidr_block = "10.1.0.0/16" tags = { - Name = "dpp-vpc" + Name = "dppa-vpc" } - } -resource "aws_subnet" "dpp-public-subnet-01" { - vpc_id = aws_vpc.dpp-vpc.id - cidr_block = "10.1.1.0/24" +resource "aws_subnet" "dppa-public_subent_01" { + vpc_id = aws_vpc.dppa-vpc.id + cidr_block = "10.1.1.0/24" map_public_ip_on_launch = "true" - availability_zone = "us-east-1a" + availability_zone = "us-east-1a" tags = { - Name = "dpp-public-subent-01" + Name = "dppa-public_subent_01" } } -resource "aws_subnet" "dpp-public-subnet-02" { - vpc_id = aws_vpc.dpp-vpc.id - cidr_block = "10.1.2.0/24" +resource "aws_subnet" "dppa-public_subent_02" { + vpc_id = aws_vpc.dppa-vpc.id + cidr_block = "10.1.2.0/24" map_public_ip_on_launch = "true" - availability_zone = "us-east-1b" + availability_zone = "us-east-1b" tags = { - Name = "dpp-public-subent-02" + Name = "dppa-public_subent_02" } } -resource "aws_internet_gateway" "dpp-igw" { - vpc_id = aws_vpc.dpp-vpc.id +resource "aws_internet_gateway" "dppa-igw" { + vpc_id = aws_vpc.dppa-vpc.id tags = { - Name = "dpp-igw" - } + Name = "dppa-igw" + } } -resource "aws_route_table" "dpp-public-rt" { - vpc_id = aws_vpc.dpp-vpc.id +resource "aws_route_table" "dppa-public-rt" { + vpc_id = aws_vpc.dppa-vpc.id route { cidr_block = "0.0.0.0/0" - gateway_id = aws_internet_gateway.dpp-igw.id + gateway_id = aws_internet_gateway.dppa-igw.id + } + tags = { + Name = "dppa -public-rt" } } -resource "aws_route_table_association" "dpp-rta-public-subnet-01" { - subnet_id = aws_subnet.dpp-public-subnet-01.id - route_table_id = aws_route_table.dpp-public-rt.id +resource "aws_route_table_association" "dppa-rta-public-subent-1" { + subnet_id = aws_subnet.dppa-public_subent_01.id + route_table_id = aws_route_table.dppa-public-rt.id } -resource "aws_route_table_association" "dpp-rta-public-subnet-02" { - subnet_id = aws_subnet.dpp-public-subnet-02.id - route_table_id = aws_route_table.dpp-public-rt.id + +resource "aws_route_table_association" "dppa-rta-public-subent-2" { + subnet_id = aws_subnet.dppa-public_subent_02.id + route_table_id = aws_route_table.dppa-public-rt.id } \ No newline at end of file diff --git a/terraform_code/dppa.pem b/terraform_code/dppa.pem new file mode 100644 index 0000000..b78e8f5 --- /dev/null +++ b/terraform_code/dppa.pem @@ -0,0 +1,7 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtz +c2gtZWQyNTUxOQAAACDY8Yb0OIGvcpQ3qyfvwxxICepvTkCqxkvYoEh3b5J48wAA +AIgM147lDNeO5QAAAAtzc2gtZWQyNTUxOQAAACDY8Yb0OIGvcpQ3qyfvwxxICepv +TkCqxkvYoEh3b5J48wAAAEAwUQIBATAFBgMrZXAEIgQgUWhRWDfVAHUQtAaxVU0w +rdjxhvQ4ga9ylDerJ+/DHEgJ6m9OQKrGS9igSHdvknjzAAAAAAECAwQF +-----END OPENSSH PRIVATE KEY-----