Selfnotes/ansible playbook, install ansible

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

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