From 323248394559b827e49cba7802e6df2eb5029a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=A4rkle?= Date: Wed, 17 May 2023 20:17:32 +0200 Subject: [PATCH] aws commands aktualisiert --- create_aws_wireguard_server.yml | 22 ++++------ headscale-server.yml | 15 +++++++ .../tasks/main.yml | 43 +++++++++++++------ roles/headscale-server/tasks/main.yml | 0 4 files changed, 54 insertions(+), 26 deletions(-) create mode 100644 headscale-server.yml rename roles/{aws_graviton_nano_spot => aws_graviton_nano}/tasks/main.yml (66%) create mode 100644 roles/headscale-server/tasks/main.yml diff --git a/create_aws_wireguard_server.yml b/create_aws_wireguard_server.yml index 645a356..e154b61 100644 --- a/create_aws_wireguard_server.yml +++ b/create_aws_wireguard_server.yml @@ -12,26 +12,20 @@ prompt: AWS Region to use for instance default: "eu-central-1" 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 prompt: Which hostname shall be registered for the host (Empty = no dns, Zone needs to be route53 managed)? default: "" private: no vars: dns_zone_name: "{{ dns_name | regex_replace('^[\\w-]+\\.', '') }}" - ansible_python_interpreter: /usr/bin/python3 roles: - - aws_graviton_nano_spot + - aws_graviton_nano -- name: include playbook for pihole - import_playbook: pihole.yml +- name: include playbook for pihole# + import_playbook: headscale-server.yml -- name: include playbook for wireguard server - import_playbook: wireguard_pihole_only.yml +#- name: include playbook for pihole# +# import_playbook: pihole.yml + +#- name: include playbook for wireguard server +# import_playbook: wireguard_pihole_only.yml diff --git a/headscale-server.yml b/headscale-server.yml new file mode 100644 index 0000000..85bd5c1 --- /dev/null +++ b/headscale-server.yml @@ -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 + diff --git a/roles/aws_graviton_nano_spot/tasks/main.yml b/roles/aws_graviton_nano/tasks/main.yml similarity index 66% rename from roles/aws_graviton_nano_spot/tasks/main.yml rename to roles/aws_graviton_nano/tasks/main.yml index 7afc50e..53bbbd0 100644 --- a/roles/aws_graviton_nano_spot/tasks/main.yml +++ b/roles/aws_graviton_nano/tasks/main.yml @@ -19,22 +19,41 @@ - proto: all cidr_ip: 0.0.0.0/0 register: security_group - -- name: create graviton spot instance - amazon.aws.ec2: + +- 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: region: "{{ aws_region }}" - spot_type: persistent - spot_wait_timeout: 120 key_name: vpn_key - group_id: "{{ security_group.group_id }}" - instance_type: "{{ aws_type }}" - image: "{{ aws_ami }}" - wait: yes + name: "{{ dns_name }}" + security_group: "{{ security_group.group_id }}" + instance_type: "t4g.nano" + image_id: "{{ aws_ami }}" instance_initiated_shutdown_behavior: terminate + network: + assign_public_ip: true + wait: true + state: running register: graviton - name: generate route53 dns entry for the instance - route53: + amazon.aws.route53: command: create overwrite: yes zone: "{{ dns_zone_name }}" @@ -44,7 +63,7 @@ value: "{{ item.public_dns_name }}" loop: "{{ graviton.instances }}" when: dns_name != "" - + - name: Wait for SSH to come up delegate_to: "{{ item.public_dns_name }}" wait_for_connection: @@ -54,7 +73,7 @@ - name: Add new instance to host group add_host: - hostname: "{{ item.public_ip }}" + hostname: "{{ item.public_ip_address }}" groupname: launched loop: "{{ graviton.instances }}" diff --git a/roles/headscale-server/tasks/main.yml b/roles/headscale-server/tasks/main.yml new file mode 100644 index 0000000..e69de29