From e6526cba40cf7d696fb289cce5b824b831c6e82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=A4rkle?= Date: Wed, 2 Dec 2020 16:04:55 +0100 Subject: [PATCH] Umstellen auf ansible --- Readme.md | 2 ++ gravitoninstance.yml | 25 ++++++++++++++++++++ roles/aws_graviton_nano_spot/tasks/main.yml | 26 +++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 Readme.md create mode 100644 gravitoninstance.yml create mode 100644 roles/aws_graviton_nano_spot/tasks/main.yml diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..94efde3 --- /dev/null +++ b/Readme.md @@ -0,0 +1,2 @@ + + ansible-galaxy collection install amazon.aws diff --git a/gravitoninstance.yml b/gravitoninstance.yml new file mode 100644 index 0000000..de393ca --- /dev/null +++ b/gravitoninstance.yml @@ -0,0 +1,25 @@ +--- +# Provisioning of a graviton server using aws spot instance +- hosts: local + vars_prompt: + - name: ssh_pub_key_file + prompt: Location of your public ssh key + default: "~/.ssh/id_rsa.pub" + - name: aws_region + prompt: AWS Region to use for instaance + default: "us-east-1" + - name: aws_ami + prompt: Disk image to use for instance (default is ubuntu 20.10 arm64) + default: "ami-01069be104eb25898" + - name: aws_type + prompt: Instance type to request + default: "t4g.nano" + - name: dns_zone_name + prompt: Route53 zone in which nameserver entry is registered + default: "appments.net" + - name: dns_host_name + prompt: Hostname that is registered in Route53 + default: "illevpn" + roles: + - aws_graviton_nano_spot + - wireguard_server diff --git a/roles/aws_graviton_nano_spot/tasks/main.yml b/roles/aws_graviton_nano_spot/tasks/main.yml new file mode 100644 index 0000000..88dbc8b --- /dev/null +++ b/roles/aws_graviton_nano_spot/tasks/main.yml @@ -0,0 +1,26 @@ +- name: copy ssh public key + amazon.aws.ec2_key: + name: vpn_key + key_material: "{{ lookup('file', '{{ ssh_pub_key_file }}') }}" + +- name: create graviton spot instance + amazon.aws.ec2: + spot_type: persistent + spot_wait_timeout: 120 + key_name: vpn_key + instance_type: "{{ aws_type }}" + image: "{{ aws_ami }}" + wait: yes + assign_public_ip: yes + instance_initiated_shutdown_behavior: terminate + register: graviton_instance + +- name: generate route53 dns entry for the instance + route53: + command: create + overwrite: yes + zone: "{{ dns_zone_name }}" + record: "{{ dns_host_name }}" + type: CNAME + ttl: 60 + value: "{{ graviton_instance.domain_name }}"