Selfnotes/ansible playbook, install ansible

DevOps

MOTOSHARE 🚗🏍️
Turning Idle Vehicles into Shared Rides & Earnings

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Owners earn. Renters ride.
🚀 Everyone wins.

Start Your Journey with Motoshare

Write a Terraform script which create a ubuntu ec2-instance and copy a ansible playbook, install ansible and run it.

Step 1 – Create ec2-instance with key and group

Step 2 – COpy playbook using file prov*

Step 3 – Install Ansible using remote prov*

Step 4 – RUn Ansinle playbook command using remote prv*

provider "aws" {
  profile = "default"
  region  = "us-west-2"
}

resource "aws_instance" "abhishek" {
  count = 3
  ami = "ami-ce5a9fa3"
  instance_type = "t2.micro"
  key_name = "ansible_aws"
  tags {
    Name = "Abhishek"
  }
}

  connection {
      type     = "ssh"
      user     = "ubuntu"
      private_key = file("abhishek-last.pem")
      #host = aws_instance.web.public_ip
      host = self.public_ip
  }
  provisioner "local-exec" {
    command = "touch devopsschool-local"
  }

  provisioner "remote-exec" {
    inline = [
      "sudo apt-get update",
      "sudo add-apt-repository --yes --update ppa:ansible/ansible",
      "sudo apt install ansible -y"
    ]
  provisioner "file" {
    source      = "abc.yml"
    destination = "/tmp/"
  } 
}Code language: PHP (php)