-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathec2_create.yml
More file actions
62 lines (56 loc) · 1.53 KB
/
ec2_create.yml
File metadata and controls
62 lines (56 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
- name: create new EC2 instance
hosts: localhost
gather_facts: no
vars:
start_idx: 0
count: 1
tasks:
- name: set name
set_fact:
vm_name: "{{ HOSTS }}" #| regex_search('(\\w*)') }}"
- name: create security group
ec2_group:
name: "wtome-ssh-all"
description: "Allow SSH from anywhere"
region: "{{ aws_region }}"
vpc_id: "{{ vpc_id }}"
rules:
- proto: tcp
ports:
- 22
cidr_ip: 0.0.0.0/0
rule_desc: "allow all on port 22"
- name: create ec2 instance
ec2:
key_name: "{{ ec2_key_name }}"
instance_type: "{{ ec2_size | default('t2.micro') }}"
image: "{{ ec2_ami | default('ami-6871a115') }}"
region: "{{ aws_region }}"
wait: yes
group: wtome-ssh-all
vpc_subnet_id: "{{ subnet_id }}"
assign_public_ip: yes
exact_count: 1
user_data: "{{ ec2_user_data | default ('') }}"
count_tag:
Name: "{{ vm_name }}-{{item}}"
instance_tags:
Name: "{{ vm_name }}-{{ item }}"
Group: "{{ HOSTS_GROUP }}"
Platform: linux
Owner: "{{ OWNER | default('ansible')}}"
register: ec2_out
loop: "{{ range(start_idx | int, (count | int)) | list }}"
- name: create inventory
add_host:
name: "{{ item.tagged_instances.0.tags.Name }}"
ansible_host: "{{ item.tagged_instances.0.public_ip }}"
groups: servers
loop: "{{ ec2_out.results }}"
- name: test connectivity
hosts: servers
gather_facts: no
tasks:
- wait_for_connection:
- setup: