-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitlab-create.yml
144 lines (129 loc) · 4.33 KB
/
gitlab-create.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
---
- hosts: localhost
connection: local
gather_facts: False
vars_files:
- /Users/eric/Work/secuber/aws/docker-base/vars/amis.yml
vars:
instance_count: 1
instance_type: t2.large
basename: gitlab
role: utils
root_size: 8
tasks:
- name: Provision a set of instances
ec2:
key_name: tchu
region: eu-west-1
zone: eu-west-1b
group:
- ssh-only
- vpc-full
# - msk-office-allow-all
# - msk-office-lan
instance_type: '{{instance_type}}'
image: "{{ docker_base_ami }}"
instance_profile_name: ec2-linux-role
wait: true
exact_count: '{{instance_count}}'
count_tag:
Role: '{{role}}'
instance_tags:
Name: '{{basename}}'
Role: '{{role}}'
volumes:
- device_name: /dev/sda1
volume_size: '{{root_size}}'
volume_type: gp2
delete_on_termination: true
register: ec2
- name: tag instances
ec2_tag:
region: eu-west-1
resource: '{{item.1["id"]}}'
tags:
Name: '{{basename}}'
with_indexed_items: ec2.tagged_instances
- name: create individual internal DNS records
route53:
command: create
private_zone: yes
overwrite: yes
zone: cybertonica.aws
record: '{{basename}}.cybertonica.aws'
type: A
ttl: 7200
value: '{{item.1.private_ip}}'
with_indexed_items: ec2.tagged_instances
- name: create individual external DNS records
route53:
command: create
private_zone: no
overwrite: yes
zone: cybertonica.aws
record: '{{basename}}.cybertonica.aws'
type: A
ttl: 7200
value: '{{item.1.public_ip}}'
with_indexed_items: ec2.tagged_instances
- debug: msg='{{ec2.tagged_instances|map(attribute="public_ip")|list}}'
# - name: create external DNS record
# route53:
# command: create
# private_zone: no
# overwrite: yes
# zone: cybertonica.aws
# record: 'flocker.cybertonica.aws'
# type: A
# ttl: 7200
# value: '{{ec2.tagged_instances|map(attribute="public_ip")|list}}'
#
# - debug: msg='{{ec2.tagged_instances|map(attribute="private_ip")|list}}'
#
# - name: create internal DNS record
# route53:
# command: create
# private_zone: yes
# overwrite: yes
# zone: cybertonica.aws
# record: 'consul.cybertonica.aws'
# type: A
# ttl: 7200
# value: '{{ec2.tagged_instances|map(attribute="private_ip")|list}}'
#
- name: Add new instance to host group
add_host: hostname={{ item.public_ip }} groupname=launched
with_items: ec2.tagged_instances
- name: Wait for SSH to come up
wait_for: host={{ item.public_dns_name }} port=22 timeout=320 state=started
with_items: ec2.tagged_instances
- name: Configure instance(s)
hosts: launched
remote_user: ubuntu
become: True
gather_facts: True
vars:
basename: gitlab
tasks:
- name: set hostname
hostname: name='{{basename}}-0{{groups["launched"].index(inventory_hostname)+1}}.cybertonica.aws'
- name: update system
apt: update_cache=yes upgrade=dist
- name: update kernel
apt: pkg=linux-image-extra-virtual-lts-wily state=present
- name: reset docker host id
file: dest=/etc/docker/key.json state=absent
- name: install AWS CLI
pip: name=awscli state=present
- name: get docker creds for CBT registry
shell: $(aws ecr get-login --region=us-east-1)
- name: install cronjob to update docker creds for registry
cron: name="update docker creds" minute="11" job="$(/usr/local/bin/aws ecr get-login --region=us-east-1)" state=present
- name: restart machine
command: shutdown -r now "Ansible updates triggered"
async: 0
poll: 0
ignore_errors: true
- name: waiting for server to come back
local_action: wait_for host="{{ inventory_hostname }}" port=22 state=started
become: false