Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save devops-school/10e93c4b2e753ed36772ff15cfe995f6 to your computer and use it in GitHub Desktop.
Save devops-school/10e93c4b2e753ed36772ff15cfe995f6 to your computer and use it in GitHub Desktop.
Terraform Install Ansible and Run Playbook Example
provider "aws" {
region = "eu-west-1"
access_key = ""
secret_key = ""
}
resource "aws_instance" "example" {
ami = "${var.ami-mine}"
instance_type = "t2.micro"
key_name = "rajesh"
tags = {
Name = "ANSIBLE"
}
connection {
type = "ssh"
user = "ec2-user"
private_key = "${file("rajesh.pem")}"
host = "${self.public_ip}"
}
provisioner "remote-exec" {
inline = [
"sudo amazon-linux-extras install ansible2 -y",
"sudo yum install git -y",
"git clone https://github.com/devops-school/ansible-hello-world-role /tmp/ans_ws",
"ansible-playbook /tmp/ans_ws/site.yaml"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment