2020-12-02 16:04:55 +01:00
|
|
|
- name: copy ssh public key
|
|
|
|
amazon.aws.ec2_key:
|
|
|
|
name: vpn_key
|
|
|
|
key_material: "{{ lookup('file', '{{ ssh_pub_key_file }}') }}"
|
|
|
|
|
2020-12-02 18:11:18 +01:00
|
|
|
- name: network security policy that allows all traffic incoming and outgoing
|
|
|
|
amazon.aws.ec2_group:
|
|
|
|
name: "vpn allow all"
|
|
|
|
description: allow all traffic/protocol/ports
|
|
|
|
region: "{{ aws_region }}"
|
|
|
|
rules:
|
|
|
|
- proto: all
|
|
|
|
cidr_ip: 0.0.0.0/0
|
|
|
|
- proto: all
|
|
|
|
group_name: "vpn allow all"
|
|
|
|
rules_egress:
|
|
|
|
- proto: all
|
|
|
|
cidr_ip: 0.0.0.0/0
|
|
|
|
register: security_group
|
|
|
|
|
2020-12-02 16:04:55 +01:00
|
|
|
- name: create graviton spot instance
|
|
|
|
amazon.aws.ec2:
|
2020-12-02 18:11:18 +01:00
|
|
|
region: "{{ aws_region }}"
|
2020-12-02 16:04:55 +01:00
|
|
|
spot_type: persistent
|
|
|
|
spot_wait_timeout: 120
|
|
|
|
key_name: vpn_key
|
2020-12-02 18:11:18 +01:00
|
|
|
group_id: "{{ security_group.group_id }}"
|
2020-12-02 16:04:55 +01:00
|
|
|
instance_type: "{{ aws_type }}"
|
|
|
|
image: "{{ aws_ami }}"
|
|
|
|
wait: yes
|
|
|
|
instance_initiated_shutdown_behavior: terminate
|
2020-12-16 11:42:13 +01:00
|
|
|
vpc_subnet_id: "subnet-3df70f5a"
|
|
|
|
assign_public_ip: yes
|
2020-12-02 18:11:18 +01:00
|
|
|
register: graviton
|
|
|
|
|
2020-12-16 11:42:13 +01:00
|
|
|
- name: generate route53 dns entry for the instance
|
|
|
|
route53:
|
|
|
|
command: create
|
|
|
|
overwrite: yes
|
|
|
|
zone: "{{ dns_zone_name }}"
|
|
|
|
record: "{{ dns_name }}"
|
|
|
|
type: CNAME
|
|
|
|
ttl: 60
|
|
|
|
value: "{{ item.public_dns_name }}"
|
|
|
|
loop: "{{ graviton.instances }}"
|
|
|
|
when: dns_name != ""
|
|
|
|
|
2020-12-02 18:11:18 +01:00
|
|
|
- name: Wait for SSH to come up
|
|
|
|
delegate_to: "{{ item.public_dns_name }}"
|
|
|
|
wait_for_connection:
|
|
|
|
delay: 60
|
|
|
|
timeout: 320
|
|
|
|
loop: "{{ graviton.instances }}"
|
|
|
|
|
|
|
|
- name: Add new instance to host group
|
|
|
|
add_host:
|
|
|
|
hostname: "{{ item.public_ip }}"
|
|
|
|
groupname: launched
|
|
|
|
loop: "{{ graviton.instances }}"
|
2020-12-02 16:04:55 +01:00
|
|
|
|
2020-12-02 22:58:17 +01:00
|
|
|
- name: Print public IP of this server
|
|
|
|
debug:
|
|
|
|
msg: Your instance has th public IP address {{ item.public_ip }}
|
|
|
|
loop: "{{ graviton.instances }}"
|