From 873cf1b8018d81ab53e1ab2e12a5c769d1ce9e85 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 11 Oct 2024 16:44:41 +0200 Subject: [PATCH] Add playbook for spawning logdetective02 Eventually started in us-east-1. Fixes: #77 --- releng/training-machine/group_vars/all.yml | 43 +++++++++++++ .../training-machine/spawn-logdetective02.yml | 62 +++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 releng/training-machine/group_vars/all.yml create mode 100644 releng/training-machine/spawn-logdetective02.yml diff --git a/releng/training-machine/group_vars/all.yml b/releng/training-machine/group_vars/all.yml new file mode 100644 index 0000000..e5d9532 --- /dev/null +++ b/releng/training-machine/group_vars/all.yml @@ -0,0 +1,43 @@ +--- +aws_new_instance: + # make sure you have [logdetective] sections in ~/.aws/config and + # ~/.aws/credentials + profile: logdetective + name: logdetective02 + + ## region: eu-west-1 + ## #image: ami-00050c079abc52c85 # F40 + ## #nah: https://gitlab.com/fedora/websites-apps/fedora-websites/fedora-websites-3.0/-/issues/317 + ## image: ami-0d97c9cabbb22e54a # F39 + ## infra_subnet: subnet-0fe1d4e0e304de666 + ## ssh_key: ansible key + ## # https://github.com/fedora-copr/logdetective/issues/77#issuecomment-2413459002 + ## security_group: sg-0a454bd8f70a679ce + ## # created semi-manually by praiskup, already has appropriate ipv{4,6} + ## eni: eni-09b10ec80f846224c + ## elastic_ip: 52.18.47.238 + ## ipv6: 2a05:d018:117:3003:7f90:e534:a956:f7f4 + + region: us-east-1 + # doh! https://gitlab.com/fedora/websites-apps/fedora-websites/fedora-websites-3.0/-/issues/317 + image: ami-0746fc234df9c1ee0 # inherited from copr-be-dev + infra_subnet: subnet-0995f6a466849f4c3 # a + # infra_subnet: subnet-09c74a3e6420a206b # b + # infra_subnet: subnet-08cadf5a14b530ac4 # c + # infra_subnet: subnet-01d4e967ab5e78005 # d + # infra_subnet: subnet-07b0b3168a353e3ee # e + ssh_key: Ansible Key + security_group: sg-00ec53e746bfe2b00 + # created semi-manually by praiskup, already has appropriate ipv{4,6} + eni: eni-00262174ef1654ef8 + elastic_ip: 34.235.77.11 + ipv6: 2600:1f18:8ee:ae00:8e6a:db65:9812:8e10 + + ## See discussion https://github.com/fedora-copr/logdetective/issues/77 and slack + instance_type: p3.16xlarge + #instance_type: p2.16xlarge + #instance_type: g5.48xlarge + #instance_type: p3dn.24xlarge + # this one is not well prepared, created via wizzard + root_volume_size: 60 + # created semi-manually by praiskup, already has appropriate ipv{4,6} diff --git a/releng/training-machine/spawn-logdetective02.yml b/releng/training-machine/spawn-logdetective02.yml new file mode 100644 index 0000000..5b72861 --- /dev/null +++ b/releng/training-machine/spawn-logdetective02.yml @@ -0,0 +1,62 @@ +--- +- name: "Start new EC2 machine" + hosts: localhost + connection: local + gather_facts: false + tasks: + - name: "create a new training machine for logdetective" + amazon.aws.ec2_instance: + name: "{{ aws_new_instance.name }}" + state: running + profile: "{{ aws_new_instance.profile }}" + region: "{{ aws_new_instance.region }}" + key_name: "{{ aws_new_instance.ssh_key }}" + count: 1 + image_id: "{{ aws_new_instance.image }}" + instance_type: "{{ aws_new_instance.instance_type }}" + detailed_monitoring: true + + # Use either network or vpc_subnet_id + security_group + network: + interfaces: + - "{{ aws_new_instance.eni }}" + # vpc_subnet_id: "{{ aws_new_instance.infra_subnet }}" + # security_group: "{{ aws_new_instance.security_group }}" + + termination_protection: false + wait: true + tags: + FedoraGroup: logdetective + volumes: + - ebs: + volume_size: "{{ aws_new_instance.root_volume_size }}" + encrypted: true + delete_on_termination: true + device_name: /dev/sda1 + register: instances_started + + - name: associate the elastic IP with the new eni + community.aws.ec2_eip: + device_id: "{{ instances_started.instances[0].network_interfaces[0].network_interface_id }}" + ip: "{{ aws_new_instance.elastic_ip }}" + in_vpc: true + region: "{{ aws_new_instance.region }}" + state: present + when: + - aws_new_instance.eni is not defined + - aws_new_instance.elastic_ip is defined + + - name: "add {{ aws_new_instance.ipv6 }} to the new machine" + ansible.builtin.command: > + aws ec2 --profile {{ aws_new_instance.profile }} assign-ipv6-addresses + --ipv6-addresses {{ aws_new_instance.ipv6 }} + --network-interface-id {{ instances_started.instances[0].network_interfaces[0].network_interface_id }} + when: + - aws_new_instance.eni is not defined + - aws_new_instance.ipv6 is defined + + - name: print ipv4 + debug: + msg: + - "Instance ID: {{ instances_started.instances[0].instance_id }}" + - "Elastic IP: {{ aws_new_instance.elastic_ip }}"