-
Notifications
You must be signed in to change notification settings - Fork 1
/
aws_cli_up.yml
96 lines (88 loc) · 2.58 KB
/
aws_cli_up.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
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# ---
# aws_cli_up.yml
#
# Levanta una maquina virtual para el laboratorio de AWS.
# ---
- hosts: 127.0.0.1
connection: local
gather_facts: yes
vars_files:
- ./vars/aws.yml
tasks:
- name: create a new ec2 key pair, returns generated private key
ec2_key:
region: '{{aws_region}}'
name: '{{aws_key_pair_name}}'
register: pair
- name: 'Create {{aws_key_pair_name}} file inside the {{secret_vars_directory}} directory'
lineinfile:
dest: '{{private_key_file}}'
line: '{{pair.key.private_key}}'
mode: 0400
create: yes
when: pair["key"]["private_key"] is defined
- name: 'Create EC2 security group for project {{ project }}'
ec2_group:
name: '{{aws_security_group_name}}'
description: 'Security group for project {{project}}'
vpc_id: '{{aws_vpc_id}}'
region: '{{aws_region}}'
rules: '{{aws_sg_rules}}'
register: sg
- name: 'Create the EC2 server on subnet {{aws_subnet_id}}'
ec2:
id: '{{ server_name_id }}'
region: '{{aws_region}}'
key_name: '{{aws_key_pair_name}}'
group_id: '{{sg.group_id}}'
instance_type: '{{aws_ec2_instance_type}}'
image: '{{aws_ec2_image}}'
wait: yes
wait_timeout: 500
count: 1
instance_tags:
Name: '{{server_name}}'
Group: '{{group}}'
Project: '{{project}}'
monitoring: yes
vpc_subnet_id: '{{aws_subnet_id}}'
assign_public_ip: '{{aws_ec2_assign_public_ip}}'
register: ec2_instances
- name: Get EC2 instance data
set_fact:
ec2: '{{ec2_instances.instances[0]}}'
- name: Set DNS records
route53:
state: present
zone: '{{domain}}'
record: '{{server_name}}.{{domain}}'
type: A
value: '{{ ec2.public_ip }}'
wait: yes
overwrite: true
register: dns
async: 1
poll: 0
- name: Add host to group '{{group}}'
add_host:
name: '{{ ec2.public_ip }}'
groups: '{{group}}'
ansible_ssh_private_key_file: '{{private_key_file}}'
ansible_user: '{{ aws_ec2_user }}'
ansible_python_interpreter: '{{aws_ec2_python_interpreter}}'
- name: Wait for SSH
wait_for:
port: 22
host: '{{ ec2.public_ip }}'
- hosts: keycloak
gather_facts: yes
become: yes
vars_files:
- ./vars/keycloak.yml
tasks:
- include_role:
name: conatest_profile
- include_role:
name: conatest_server_setup
- include_role:
name: conatest_ubuntu_aws_cli