-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate_instance.yml
36 lines (34 loc) · 919 Bytes
/
create_instance.yml
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
- hosts: localhost
vars_files:
- aws_credential.yml
- instance_vars.yml
tasks:
- package:
name: python3-pip
state: present
- pip:
name: boto3
- community.aws.ec2_instance:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
region: "{{ aws_region }}"
tags:
Name: "{{ name }}"
key_name: "{{ key_pair }}"
instance_type: "{{ instance_type }}"
image_id: "{{ aws_image }}"
vpc_subnet_id: "{{ subnet }}"
network:
assign_public_ip: true
security_group: default
count: "{{ count }}"
register: ec2
- debug:
var: ec2
- set_fact:
private_ip: "{{ ec2.instances | map(attribute='private_ip_address') | list }}"
- debug:
var: private_ip
- template:
src: inventory.j2
dest: inventory