Created
November 12, 2021 01:03
-
-
Save iamgini/c7db412a58ec5c1647d261a65a9425e0 to your computer and use it in GitHub Desktop.
Ansible for AWS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create ec2 | |
- name: Launching EC2 instances | |
community.aws.ec2_instance: | |
#aws_access_key: "{{ec2_access_key}}" | |
#aws_secret_key: "{{ec2_secret_key}}" | |
profile: "{{ aws_boto_profile }}" | |
key_name: "{{ aws_demo_key }}" | |
security_group: "{{ aws_security_group }}" | |
instance_type: "{{ item.value.instance_type }}" | |
image_id: "{{ aws_ami_id }}" | |
state: present | |
wait: yes | |
wait_timeout: 300 | |
region: "{{ aws_region }}" | |
tags: | |
Name: "{{ item.value.name }}" | |
detailed_monitoring: no | |
vpc_subnet_id: "{{ vpc_subnet_list | random }}" | |
network: | |
assign_public_ip: yes | |
loop: "{{ lookup('dict', ec2_new_list, wantlist=True) }}" | |
# create security group | |
- name: Create Security group | |
amazon.aws.ec2_group: | |
profile: "{{ aws_boto_profile }}" | |
name: "{{ aws_security_group }}" | |
description: 'Security Group with SSH and HTTP rules' | |
vpc_id: "{{ aws_vpc_id }}" | |
region: "{{ aws_region }}" | |
rules: | |
- proto: tcp | |
ports: | |
- 80 | |
cidr_ip: 0.0.0.0/0 | |
rule_desc: allow all on port 80 | |
- proto: tcp | |
ports: | |
- 22 | |
cidr_ip: 0.0.0.0/0 | |
rule_desc: allow all on port 22 | |
# create elb | |
- name: Create Amazon ELB | |
amazon.aws.ec2_elb_lb: | |
profile: "{{ aws_boto_profile }}" | |
name: "{{ aws_elb_app_lb }}" | |
region: "{{ aws_region }}" | |
zones: | |
- "{{ ap_zone1 }}" | |
- "{{ ap_zone2 }}" | |
listeners: | |
- protocol: http | |
load_balancer_port: 80 | |
instance_port: 80 | |
proxy_protocol: True | |
state: present | |
register: elbcreated | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment