-
Notifications
You must be signed in to change notification settings - Fork 4
/
ansible-create-ec2.yml
67 lines (64 loc) · 2.04 KB
/
ansible-create-ec2.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
# aws-vault exec sso-sandbox-account-admin -- ansible-playbook ansible-create-ec2.yml
---
- name: Launch EC2 Sandbox Instance
hosts: localhost
gather_facts: no
vars_prompt:
- name: instance_name
prompt: instance_name
private: false
default: "{{lookup('env', 'USER')}}-dev"
- name: instance_type
prompt: instance_type
default: "c6i.2xlarge"
private: false
- name: image_id
prompt: image_id
default: "ami-007855ac798b5175e" # ubuntu 22.04
private: false
tasks:
- name: Load arguments from 1Password
block:
- shell: op item get 'EC2 Sandbox' --format json | jq '.fields | INDEX(.label)'
register: out
- set_fact:
"{{item}}": "{{(out.stdout | from_json)[item].value}}"
loop:
- key_name
- key_path
- region
- security_groups
- user
- vpc_subnet_id
- name: "Launch {{instance_type}} instance named {{instance_name}}"
ec2_instance:
name: "{{instance_name}}"
instance_type: "{{instance_type}}"
region: "{{region}}"
image_id: "{{image_id}}"
vpc_subnet_id: "{{vpc_subnet_id}}"
key_name: "{{key_name}}"
security_groups: "{{security_groups}}"
volumes:
- device_name: /dev/sda1 # root volume
ebs:
volume_size: 256 # GB
volume_type: gp3
delete_on_termination: true
iops: 10000
#throughput: 250
wait: yes
register: ec2_instance
- name: Update ~/.ssh/config file
blockinfile:
path: "~/.ssh/config"
block: |
Host {{instance_name}}
HostName {{ec2_instance.instances[0].private_ip_address}}
User {{user}}
IdentityFile "{{key_path}}"
marker: "# {mark} ANSIBLE MANAGED BLOCK for {{instance_name}}"
- debug:
msg:
- Setup: ansible-playbook -i '{{instance_name}},' ansible-ubuntu.yml
- Connect: ssh {{instance_name}}"