Skip to content

Commit

Permalink
ansible role : ec2_creation on aws using ansible
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalk17 authored Jul 3, 2024
1 parent 7de1acd commit 769f474
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ansible/roles/ec2_create/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: start an instance with a public IP address
amazon.aws.ec2_instance:
name: "{{ item.name }}"
instance_type: "{{ type }}" # pick from /vars/main.yaml
region: ap-south-1
security_group: default
network:
assign_public_ip: true
image_id: "{{ item.image }}"
aws_access_key: "{{ aws_access_key }}" # to access aws # from ansible vault
aws_secret_key: "{{ aws_secret_key }}"
tags:
Environmient: Testing
with_items:
- { image: ami-01376101673c89611, name: amz-1 }
- { image: ami-01376101673c89611, name: amz-2 }
- { image: ami-0ad21ae1d0696ad58, name: ubuntu-1}
- { image: ami-0ad21ae1d0696ad58, name: ubuntu-2}

# Ansible won't create multiple instances with the same parameters unless specified differently.
# Since the AMI ID is the same for two amz instances and two ubuntu instances,
# if I execute the playbook without providing unique names, it may not create separate instances.
# By providing unique names for each instance, I ensure the creation of 4 distinct instances, even if the AMI IDs are the same.
2 changes: 2 additions & 0 deletions ansible/roles/ec2_create/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
type: t2.micro
8 changes: 8 additions & 0 deletions ansible/roles/ec2_create_main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- hosts: localhost
become: yes
gather_facts: true
connection: local

roles:
- ec2_create
10 changes: 10 additions & 0 deletions ansible/roles/group_vars/all/pass.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$ANSIBLE_VAULT;1.1;AES256
31643261363130373733303961373630623133393631316531353366346538346239653233363230
3837316665303631353438343736393438663633626634310a363735353238323739373761366632
66393533646235626164383936323233616263333664366334613361313739363530643932616465
6565326332333133350a623235323265313266643261353333323162343530633337373538626635
62333064626330656331356335636430376564653231646539633335383034303330353237633234
32663939353765653038623032393262393131313034386633643638643934343962313132663332
30303964313733346666393632363230336338383539333436653561613964363035646137326162
31376639323333393964373265323933383564373038653862373339356464643264323530373731
65323064336638646464646330323135336238653438333665333762393836666533

0 comments on commit 769f474

Please sign in to comment.