Selfnotes/ansible playbook, install ansible

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/"
  } 
}