-
Notifications
You must be signed in to change notification settings - Fork 0
/
bastion-instance.yaml
65 lines (59 loc) · 1.78 KB
/
bastion-instance.yaml
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
---
- name: Configure Bastion Host for Vprofile Project
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Import VPC Setup Variable
include_vars: vars/vpc_setup
- name: Import VPC Setup Variable
include_vars: vars/vpc_output_vars
- name: Create vprofile EC2 Key
ec2_key:
name: vprofile-key
region: "{{ region }}"
register: key_out
- name: Save Private Key into File bastion-key.pem
ansible.builtin.copy:
content: "{{ key_out.key.private_key }}"
dest: "./bastion-key.pem"
mode: 0600
when: key_out.changed
- name: Create Security Group for Bastion Host
ec2_group:
name: bastion-host-sg
description: Allow port 22 from everywhere and all port within sg
region: "{{ region }}"
vpc_id: "{{ vpcid }}"
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: "{{ my_ip }}"
register: bastionsg_out
- name: Creating Bastion Host
ec2:
key_name: vprofile-key
region: "{{ region }}"
instance_type: t2.micro
image: "{{ bastion_ami }}"
wait: yes
wait_timeout: 300
instance_tags:
Name: "bastion_host"
Project: vprofile
Owner: DevOps Team
exact_count: 1
count_tag:
Name: "bastion_host"
Project: vprofile
Owner: DevOps Team
group_id: "{{ bastionsg_out.group_id }}"
vpc_subnet_id: "{{ pubsub1id }}"
register: bastionhost_out
- name: Insert/Update "bastion_sgid" in vars/vpc_output_vars
ansible.builtin.blockinfile:
path: vars/vpc_output_vars
backup: yes
block: |
bastion_sgid: {{ bastionsg_out.group_id }}