aws commands aktualisiert

This commit is contained in:
Stefan Märkle 2023-05-17 20:17:32 +02:00
parent 66cdd276c2
commit 3232483945
4 changed files with 54 additions and 26 deletions

View File

@ -12,26 +12,20 @@
prompt: AWS Region to use for instance prompt: AWS Region to use for instance
default: "eu-central-1" default: "eu-central-1"
private: no private: no
- name: aws_ami
prompt: Disk image to use for instance (default is debian buster arm64)
default: "ami-0e70ab85b58b23a77"
private: no
- name: aws_type
prompt: Instance type to request
default: "t4g.nano"
private: no
- name: dns_name - name: dns_name
prompt: Which hostname shall be registered for the host (Empty = no dns, Zone needs to be route53 managed)? prompt: Which hostname shall be registered for the host (Empty = no dns, Zone needs to be route53 managed)?
default: "" default: ""
private: no private: no
vars: vars:
dns_zone_name: "{{ dns_name | regex_replace('^[\\w-]+\\.', '') }}" dns_zone_name: "{{ dns_name | regex_replace('^[\\w-]+\\.', '') }}"
ansible_python_interpreter: /usr/bin/python3
roles: roles:
- aws_graviton_nano_spot - aws_graviton_nano
- name: include playbook for pihole - name: include playbook for pihole#
import_playbook: pihole.yml import_playbook: headscale-server.yml
- name: include playbook for wireguard server #- name: include playbook for pihole#
import_playbook: wireguard_pihole_only.yml # import_playbook: pihole.yml
#- name: include playbook for wireguard server
# import_playbook: wireguard_pihole_only.yml

15
headscale-server.yml Normal file
View File

@ -0,0 +1,15 @@
---
# Install headscale
- name: Install headscale
hosts: launched
remote_user: admin
become: true
vars_prompt:
- name: install_headscale
prompt: Shall the headscale server software be installed (Defaults to false)?
default: false
private: no
roles:
- role: headscale-server
when: install_headscale

View File

@ -19,22 +19,41 @@
- proto: all - proto: all
cidr_ip: 0.0.0.0/0 cidr_ip: 0.0.0.0/0
register: security_group register: security_group
- name: create graviton spot instance - name: find arm64 ami for debian
amazon.aws.ec2: 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:
region: "{{ aws_region }}" region: "{{ aws_region }}"
spot_type: persistent
spot_wait_timeout: 120
key_name: vpn_key key_name: vpn_key
group_id: "{{ security_group.group_id }}" name: "{{ dns_name }}"
instance_type: "{{ aws_type }}" security_group: "{{ security_group.group_id }}"
image: "{{ aws_ami }}" instance_type: "t4g.nano"
wait: yes image_id: "{{ aws_ami }}"
instance_initiated_shutdown_behavior: terminate instance_initiated_shutdown_behavior: terminate
network:
assign_public_ip: true
wait: true
state: running
register: graviton register: graviton
- name: generate route53 dns entry for the instance - name: generate route53 dns entry for the instance
route53: amazon.aws.route53:
command: create command: create
overwrite: yes overwrite: yes
zone: "{{ dns_zone_name }}" zone: "{{ dns_zone_name }}"
@ -44,7 +63,7 @@
value: "{{ item.public_dns_name }}" value: "{{ item.public_dns_name }}"
loop: "{{ graviton.instances }}" loop: "{{ graviton.instances }}"
when: dns_name != "" when: dns_name != ""
- name: Wait for SSH to come up - name: Wait for SSH to come up
delegate_to: "{{ item.public_dns_name }}" delegate_to: "{{ item.public_dns_name }}"
wait_for_connection: wait_for_connection:
@ -54,7 +73,7 @@
- name: Add new instance to host group - name: Add new instance to host group
add_host: add_host:
hostname: "{{ item.public_ip }}" hostname: "{{ item.public_ip_address }}"
groupname: launched groupname: launched
loop: "{{ graviton.instances }}" loop: "{{ graviton.instances }}"

View File