still working on aws

This commit is contained in:
n0mad1k
2025-05-02 12:06:09 -04:00
parent a86f9a9d25
commit f6d08e84eb
5 changed files with 510 additions and 239 deletions
+92
View File
@@ -0,0 +1,92 @@
---
# AWS Shared Infrastructure Deployment Playbook
- name: Deploy shared AWS infrastructure
hosts: localhost
gather_facts: false
connection: local
vars_files:
- vars.yaml
vars:
# Deployment identifiers
deployment_id: "{{ deployment_id | default('') }}"
infra_name: "infra-{{ deployment_id }}"
# Region settings
split_regions: "{{ c2_region is defined and redirector_region is defined and c2_region != redirector_region }}"
deployment_region: "{{ aws_region | default(aws_region_choices | random) }}"
tasks:
- name: Validate AWS credentials
assert:
that:
- aws_access_key is defined and aws_access_key != ""
- aws_secret_key is defined and aws_secret_key != ""
fail_msg: "AWS credentials are required"
- name: Skip shared infrastructure if using split regions
meta: end_play
when: split_regions | bool
- name: Create shared VPC
amazon.aws.ec2_vpc_net:
name: "{{ infra_name }}-vpc"
cidr_block: "10.0.0.0/16"
region: "{{ deployment_region }}"
tags:
Name: "{{ infra_name }}-vpc"
deployment_id: "{{ deployment_id }}"
state: present
register: vpc_result
- name: Store shared VPC ID
set_fact:
shared_vpc_id: "{{ vpc_result.vpc.id }}"
- name: Create internet gateway
amazon.aws.ec2_vpc_igw:
vpc_id: "{{ shared_vpc_id }}"
region: "{{ deployment_region }}"
state: present
tags:
Name: "{{ infra_name }}-igw"
deployment_id: "{{ deployment_id }}"
register: igw_result
- name: Create subnet
amazon.aws.ec2_vpc_subnet:
vpc_id: "{{ shared_vpc_id }}"
cidr: "10.0.1.0/24"
region: "{{ deployment_region }}"
az: "{{ deployment_region }}a"
map_public: yes
tags:
Name: "{{ infra_name }}-subnet"
deployment_id: "{{ deployment_id }}"
register: subnet_result
- name: Create routing table
amazon.aws.ec2_vpc_route_table:
vpc_id: "{{ shared_vpc_id }}"
region: "{{ deployment_region }}"
tags:
Name: "{{ infra_name }}-rtb"
deployment_id: "{{ deployment_id }}"
routes:
- dest: "0.0.0.0/0"
gateway_id: "{{ igw_result.gateway_id }}"
subnets:
- "{{ subnet_result.subnet.id }}"
register: route_table_result
- name: Write infrastructure info to state file
copy:
content: |
{
"vpc_id": "{{ shared_vpc_id }}",
"subnet_id": "{{ subnet_result.subnet.id }}",
"igw_id": "{{ igw_result.gateway_id }}",
"region": "{{ deployment_region }}",
"deployment_id": "{{ deployment_id }}"
}
dest: "infrastructure_state.json"
mode: "0600"