Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Aws Ansible, added elastic IP. #91

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 43 additions & 23 deletions playbooks/providers/aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
butane_input_template: "../templates/forem.yml.j2"
butane_aws_s3: true
butane_aws_s3_url: "https://forem-selfhost-{{ app_domain |replace('.', '-') }}-ign.s3.{{ fcos_aws_region }}.amazonaws.com/forem.ign"
register: butane_ignition_stdout

- amazon.aws.ec2_vpc_net_info:
filters:
Expand All @@ -48,6 +49,7 @@
- name: Set forem_vpc_id fact
ansible.builtin.set_fact:
forem_vpc_id: "{{ forem_vpc_info['vpcs'][0]['vpc_id'] }}"
register: forem_vpc_id_fact

- name: Gather info about VPC subnets
amazon.aws.ec2_vpc_subnet_info:
Expand Down Expand Up @@ -75,9 +77,10 @@
- name: "Generate list of route tables for {{ forem_vpc_id }}"
set_fact:
forem_vpcd_route_table_ids: "{{ forem_vpc_route_table.route_tables|map(attribute='id')|list }}"
register: forem_vpcd_route_table_ids_fact

- name: "Create S3 VPC endpoint in {{ forem_vpc_id }}"
community.aws.ec2_vpc_endpoint:
amazon.aws.ec2_vpc_endpoint:
state: present
region: "{{ fcos_aws_region }}"
vpc_id: "{{ forem_vpc_id }}"
Expand All @@ -89,6 +92,7 @@
- name: Set forem_vpc_s3_endpoint_id fact
set_fact:
forem_vpc_s3_endpoint_id: "{{ forem_vpc_s3_endpoint.result.vpc_endpoint_id }}"
register: forem_vpc_s3_endpoint_id_fact

- name: Wait for S3 VPC Endpoint
pause:
Expand Down Expand Up @@ -120,23 +124,25 @@
}
]
}
register: forem_ign_bucket

- name: "Upload butane_ignition_stdout to forem-selfhost-{{ app_domain |replace('.', '-') }}-ign"
amazon.aws.aws_s3:
amazon.aws.s3_object:
bucket: "forem-selfhost-{{ app_domain |replace('.', '-') }}-ign"
object: "/forem.ign"
object: "forem.ign"
content: "{{ butane_ignition_stdout | to_json | string }}"
mode: put
region: "{{ fcos_aws_region }}"
profile: "{{ fcos_aws_profile }}"
register: forem_ign_s3
register: forem_ign_s3

- name: Create Forem SSH key
amazon.aws.ec2_key:
name: "forem-{{ app_domain }}"
key_material: "{{ ssh_key }}"
profile: "{{ fcos_aws_profile }}"
region: "{{ fcos_aws_region }}"
register: forem_ssh_key

- name: "Create Forem security group for {{ app_domain }}"
amazon.aws.ec2_group:
Expand Down Expand Up @@ -168,30 +174,28 @@
register: forem_security_group

- name: "Launch Forem instance for {{ app_domain }}"
amazon.aws.ec2:
amazon.aws.ec2_instance:
key_name: "forem-{{ app_domain }}"
region: "{{ fcos_aws_region }}"
profile: "{{ fcos_aws_profile }}"
group: "forem-{{ app_domain }}"
security_groups: forem-{{ app_domain }}
instance_type: "{{ fcos_aws_size }}"
image: "{{ fcos_aws_image }}"
image_id: "{{ fcos_aws_image }}"
wait: yes
wait_timeout: 500
vpc_subnet_id: "{{ forem_subnet_info.subnets | map(attribute='id') | list | first }}"
volumes:
- device_name: /dev/xvda
volume_type: gp2
volume_size: "{{ fcos_aws_ebs_size }}"
encrypted: yes
delete_on_termination: no
monitoring: yes
assign_public_ip: yes
ebs:
volume_type: gp2
volume_size: "{{ fcos_aws_ebs_size }}"
delete_on_termination: no
detailed_monitoring: yes
network:
assign_public_ip: yes
groups: forem-{{ app_domain }}
user_data: "{{ butane_boot_ignition_stdout | to_json | string }}"
instance_tags:
App: "forem"
Domain: "{{ app_domain }}"
Name: "forem-{{ app_domain }}"
count_tag:
tags:
App: "forem"
Domain: "{{ app_domain }}"
Name: "forem-{{ app_domain }}"
Expand All @@ -201,23 +205,39 @@
- name: Wait 300 seconds for port 22 to become open
wait_for:
port: 22
host: "{{ forem_ec2_instance.tagged_instances | map(attribute='public_ip') | list | first }}"
host: "{{ forem_ec2_instance.instances[0].public_ip_address }}"
delay: 10
connection: local

- name: Associate Elastic IP with Forem instance
amazon.aws.ec2_eip:
device_id: "{{ forem_ec2_instance.instances[0].instance_id }}"
region: "{{ fcos_aws_region }}"
profile: "{{ fcos_aws_profile }}"
in_vpc: yes
reuse_existing_ip_allowed: yes
register: forem_ec2_eip

- name: Wait 30 seconds for Elastic IP to be associated
pause:
seconds: 30

- name: "Delete object forem-selfhost-{{ app_domain |replace('.', '-') }}-ign/forem.ign from S3"
amazon.aws.aws_s3:
bucket: "forem-selfhost-{{ app_domain |replace('.', '-') }}-ign"
object: "/forem.ign"
object: "forem.ign"
mode: delobj
region: "{{ fcos_aws_region }}"
profile: "{{ fcos_aws_profile }}"
register: forem_ign_s3_delete

- name: Output EC2 setup message
ansible.builtin.debug:
msg:
- "The public IPv4 IP Address for {{ app_domain }} is {{ forem_ec2_instance.tagged_instances | map(attribute='public_ip') | list | first }}"
- "Please add an A entry for {{ app_domain }} that points to {{ forem_ec2_instance.tagged_instances | map(attribute='public_ip') | list | first }}"
- "The public IPv4 IP Address for {{ app_domain }} is {{ forem_ec2_eip.public_ip }}"
- "Please add an A entry for {{ app_domain }} that points to {{ forem_ec2_eip.public_ip }}"
- "Example:"
- " {{ app_domain }} IN A {{ forem_ec2_instance.tagged_instances | map(attribute='public_ip') | list | first }}"
- " {{ app_domain }} IN A {{ forem_ec2_eip.public_ip }}"
- "Once you have DNS resolving to this EC2 instance please read the Forem Admin Docs: https://admin.forem.com/"
register: forem_ec2_instance_setup_message