This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
forked from mredar/aspace_deploy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_aspace_instance.yml
76 lines (76 loc) · 2.69 KB
/
create_aspace_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
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
# Create new aspace instance for a new client
# This will launch into the private VPC
# Needs to be run from the ingest front machine
#
---
- hosts: localhost
connection: local
gather_facts: no
become: yes
tasks:
- fail: msg='Need to set client name by adding --extra-vars "client_name=<new client name>" to ansible-playbook call'
when: client_name == None
- debug: var=client_name
- name: include client specific variables
include_vars: "host_vars/{{ client_name }}.yml"
- name: create a new aspace instance in the private vpc
local_action:
module: ec2
count: 1
state: present
region: "{{ region }}"
key_name: "{{ key_name }}"
image: "{{ image }}"
instance_type: "{{ instance_type }}"
instance_profile_name: aspace-instance
group_id: [ "{{ sec_grp_ingest_private_id }}" ]
wait: true
wait_timeout: 500
vpc_subnet_id: "{{ subnet_id_private }}"
termination_protection: yes
instance_tags:
project: "{{ project }}"
Name: "aspace-{{ aspace_version }}-{{ client_name }}"
Program: "{{ tag_cdl_program }}"
Environment: "{{ tag_cdl_environment }}"
Service: "{{ tag_cdl_service }}"
volumes:
- device_name: /dev/xvda
device_type: gp2
volume_size: 16
delete_on_termination: yes
register: aspace_instance
- debug: var=aspace_instance
- debug: msg="Instance id {{ aspace_instance.instance_ids.0 }}"
- name: get associated volume
ec2_vol:
region: "{{ region }}"
instance: "{{ aspace_instance.instance_ids.0 }}"
state: list
register: volumes_out
- name: tag associated volume
ec2_tag:
resource: "{{ item.id }}"
region: "{{ region }}"
tags:
project: "{{ project }}"
Name: "aspace-{{ aspace_version }}-{{ client_name }}"
Program: "{{ tag_cdl_program }}"
Environment: "{{ tag_cdl_environment }}"
Service: "{{ tag_cdl_service }}"
with_items: "{{ volumes_out.volumes | default([]) }}"
- name: create version group in hosts file
lineinfile:
dest: ./hosts
line: "[{{ aspace_version }}]"
insertafter: localhost
- name: add host to version group in hosts file
lineinfile:
dest: ./hosts
line: "{{ client_name }}-{{ aspace_version }}"
insertafter: "^\\[{{ aspace_version }}\\]$"
- name: save aspace instance information to hosts
lineinfile:
dest: ./hosts
line: "{{ client_name }}-{{ aspace_version }} ansible_ssh_host={{ aspace_instance.instances.0.private_ip}} ansible_ssh_private_key_file=~/.ssh/cluster.pem client_name={{ client_name}}"
insertafter: "[aspace_instances]"