84 lines
2.1 KiB
YAML
Raw Normal View History

2020-12-02 16:04:55 +01:00
- name: copy ssh public key
amazon.aws.ec2_key:
region: "{{ aws_region }}"
2020-12-02 16:04:55 +01:00
name: vpn_key
key_material: "{{ lookup('file', '{{ ssh_pub_key_file }}') }}"
2020-12-28 15:44:22 +01:00
region: "{{ aws_region }}"
2020-12-02 16:04:55 +01:00
2020-12-02 18:11:18 +01:00
- name: network security policy that allows all traffic incoming and outgoing
amazon.aws.ec2_group:
2020-12-28 15:44:22 +01:00
region: "{{ aws_region }}"
2020-12-02 18:11:18 +01:00
name: "vpn allow all"
description: allow all traffic/protocol/ports
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
2023-05-17 20:17:32 +02:00
- name: find arm64 ami for debian
amazon.aws.ec2_ami_info:
region: "{{ aws_region }}"
owners: amazon
filters:
name: "debian-11-arm64-20*"
architecture: "arm64"
register: amis
- name: Extract the most recently created AMI from the list
ansible.builtin.set_fact:
aws_ami: "{{ amis.images[-1].image_id }}"
- name: debug
debug:
var: aws_ami
- name: create graviton instance
amazon.aws.ec2_instance:
2020-12-02 18:11:18 +01:00
region: "{{ aws_region }}"
2020-12-02 16:04:55 +01:00
key_name: vpn_key
2023-05-17 20:17:32 +02:00
name: "{{ dns_name }}"
security_group: "{{ security_group.group_id }}"
instance_type: "t4g.nano"
image_id: "{{ aws_ami }}"
2020-12-02 16:04:55 +01:00
instance_initiated_shutdown_behavior: terminate
2023-05-17 20:17:32 +02:00
network:
assign_public_ip: true
wait: true
state: running
2020-12-02 18:11:18 +01:00
register: graviton
- name: generate route53 dns entry for the instance
2023-05-17 20:17:32 +02:00
amazon.aws.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 != ""
2023-05-17 20:17:32 +02:00
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:
2023-05-17 20:17:32 +02:00
hostname: "{{ item.public_ip_address }}"
2020-12-02 18:11:18 +01:00
groupname: launched
loop: "{{ graviton.instances }}"
2020-12-02 16:04:55 +01:00
- name: Print public IP of this server
debug:
2023-05-19 10:49:23 +02:00
msg: Your instance has th public IP address {{ item.public_ip_address }}
loop: "{{ graviton.instances }}"