Terraform Assignment – 2 by Johnson
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
Ansible playbook demo.yaml
-name= install nginx
hosts= webserver
tasks=
-name: install nginx in server
yum:
name: httpd
state: latest
Terraform script to insstall ansible and python
provider “aws” {
access_key = “*******************”
secret_key = “*********************”
region = “eu-west-3”
}
resource “aws_instance” “web” {
ami = “ami-12345”
instance_type = “t3.micro”
count = 1
tags = {
Name = “Demo”
}
}
provisioner “file” {
source = “etc/demo.yaml”
destination = “etc/demo.yaml”
}
provisioner “remote-exec” {
inline = [“sudo apt update”, “sudo apt install python3 -y”, “sudo apt install ansible -y”]
connection {
host = self.ipv4_address
type = “ssh”
user = “root”
private_key = file(var.pvt_key)
}
}
provisioner “local-exec” {
command = “ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root -i ‘${self.ipv4_address},’ –private-key ${var.pvt_key} -e ‘pub_key=${var.pub_key}’ install-apache.yml”
}
}