-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAWS machine creation and run ansible on remote host.txt
61 lines (52 loc) · 1.41 KB
/
AWS machine creation and run ansible on remote host.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
imran@imran-VirtualBox:~/Downloads$ more ansible.cfg
[defaults]
remote_user = ec2-user
host_key_checking = False
imran@imran-VirtualBox:~/Downloads$ more play.yml
- hosts: all
tasks:
- name: execute command
command: mkdir multicmd
imran@imran-VirtualBox:~/Downloads$ more main.tf
provider "aws" {
region = "us-east-2"
access_key = "Your Key"
secret_key = "Your Key"
}
resource "aws_security_group" "allow_ssh" {
name = "allow_ssh"
description = "Allow SSH inbound traffic"
ingress {
description = "SSH into VPC"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
description = "Outbound Allowed"
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "myec2" {
ami = "ami-00dfe2c7ce89a450b"
instance_type = "t2.micro"
key_name = "MyPAIR"
associate_public_ip_address = true
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
provisioner "remote-exec" {
inline = ["echo 'hello world'" ]
connection {
type = "ssh"
user = "ec2-user"
private_key = file("./MyPAIR.pem")
host = self.public_ip
}
}
provisioner "local-exec" {
command = "ansible-playbook -i ${aws_instance.myec2.public_ip}, --private-key ./MyPAIR.pem play.yml"
}
}