Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nelabhotlaR/6e992f7ec90d025d250f400c155ca393 to your computer and use it in GitHub Desktop.
Save nelabhotlaR/6e992f7ec90d025d250f400c155ca393 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