Created
December 21, 2019 10:59
-
-
Save devops-school/10e93c4b2e753ed36772ff15cfe995f6 to your computer and use it in GitHub Desktop.
Terraform Install Ansible and Run Playbook Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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