forked from 1homas/ISE_with_Meraki_in_AWS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathise_in_aws.ping_vm.yaml
More file actions
108 lines (97 loc) · 2.99 KB
/
Copy pathise_in_aws.ping_vm.yaml
File metadata and controls
108 lines (97 loc) · 2.99 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
- name: Create SG-Ping+SSH Security Group
amazon.aws.ec2_group:
name: SG-Ping+SSH
description: Allow Ping and SSH to Linux VM
vpc_id: "{{ vpc.vpc.id }}"
region: "{{ aws_region }}"
rules:
- proto: icmp
from_port: -1
to_port: -1
cidr_ip: "{{ aws_public_access_cidr}}" # any
rule_desc: Allow ICMP Ping
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: "{{ aws_public_access_cidr}}" # any
rule_desc: Allow SSH
rules_egress:
- proto: all
cidr_ip: 0.0.0.0/0 # any
tags:
Name: SG-Ping+SSH
project: "{{ project_name }}"
started: "{{ '%Y-%m-%dT%H:%M:%S-%Z' | strftime }}"
register: sg_ping_ssh
# - name: Show sg_ping_ssh
# ansible.builtin.debug: var=sg_ping_ssh
#
# 💡 Must use the community.aws.ec2_instance module which supports the
# `user_data` field for inclusion of the Meraki vMX Authentication Token!
#
- name: Create Ping_VM
community.aws.ec2_instance:
state: running
name: "{{ pingvm_name }}"
region: "{{ aws_region }}"
vpc_subnet_id: "{{ subnet_private.subnet.id }}"
image_id: "{{ aws_linux_ami }}"
instance_type: "{{ aws_linux_instance_type }}"
key_name: "{{ ssh_keypair_name }}" # SSH Keypair Name
security_group: "{{ sg_ping_ssh.group_name }}"
network:
assign_public_ip: yes
delete_on_termination: yes
private_ip_address: "{{ pingvm_private_ip }}"
volumes:
- device_name: /dev/xvda
ebs:
delete_on_termination: true
volume_size: 10
wait: yes
tags:
Name: "{{ pingvm_name }}"
project: "{{ project_name }}"
started: "{{ '%Y-%m-%dT%H:%M:%S-%Z' | strftime }}"
register: ping_vm
- name: Show SSH Commands for Instance
ansible.builtin.debug:
msg: |
_
,--(_)
_/ ;-._\ ping {{ ping_vm.instances[0].public_ip_address }}
(_)( ) ) ping {{ ping_vm.instances[0].private_ip_address }}
\ ;-'_/ ssh -i {{ ssh_keypair_private_key }} ec2-user@{{ ping_vm.instances[0].private_ip_address }}
`--(_)
#
# Advertise the same internal IP for public and private DNS
#
- name: Add public DNS entry for the PingVM
when: domain_name is defined
community.aws.route53:
state: present
zone: "{{ domain_name }}"
record: "pingvm.{{ domain_name }}"
overwrite: yes
private_zone: no
type: A
ttl: 7200
value: "{{ pingvm_private_ip }}"
wait: no
- name: Add private DNS entry for the PingVM
when: domain_name is defined
community.aws.route53:
state: present
zone: "{{ domain_name }}"
record: "pingvm.{{ domain_name }}"
overwrite: yes
private_zone: yes
type: A
ttl: 7200
value: "{{ pingvm_private_ip }}"
wait: no
...