-
Notifications
You must be signed in to change notification settings - Fork 4
/
provision.yml
77 lines (70 loc) · 2.3 KB
/
provision.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
- name: Configuring environment
hosts: localhost
connection: local
vars_files:
- group_vars/nomad/vars
- group_vars/nomad/secret_vars
vars:
count: '{{ cluster_size - 1 }}' # UDF
tasks:
- name: creating nomad clients
linode.cloud.instance:
label: '{{ instance_prefix }}-client-{{ item | int + 1 }}-{{ uuid }}'
api_token: '{{ api_token }}'
type: '{{ type }}'
region: '{{ region }}'
image: '{{ image }}'
root_pass: '{{ root_pass }}'
authorized_keys: '{{ ssh_keys }}'
private_ip: true
stackscript_id: '1226547'
ua_prefix: 'marketplace-nomad-client-occ'
tags: '{{ cluster_uuid }}'
state: present
with_sequence: count='{{ count }}'
- name: get info about the client instances
linode.cloud.instance_info:
api_token: '{{ api_token }}'
label: '{{ instance_prefix }}-client-{{ item | int }}-{{ uuid }}'
register: client_info
with_sequence: count='{{ cluster_size }}'
- name: update group_vars
blockinfile:
path: ./group_vars/nomad/vars
marker: "# {mark} INSTANCE VARS"
block: |
#jinja2: trim_blocks:False
nomad_data:
client:
{%- for count in range(cluster_size) %}
- nomad-client-{{ count + 1 }}:
instance:
hostname: {{ client_info.results[count].instance.label | replace('_', '-') }}
ip_pub1: {{ client_info.results[count].instance.ipv4[0] }}
ip_priv1: {{ client_info.results[count].instance.ipv4[1] }}
{%- endfor %}
- name: test connectivity
ping:
with_items: "{{ item.instance.ipv4[0] }}"
loop:
- "{{ client_info.results }}"
- name: update inventory
blockinfile:
path: ./hosts
marker: "# {mark} NOMAD LINODES"
block: |
#jinja2: trim_blocks:False
[nomad_cluster]
[nomad_client]
localhost ansible_connection=local user=root
{%- for count in range(cluster_size -1 ) %}
{{ client_info.results[count + 1].instance.ipv4[0] }}
{%- endfor %}
- name: wait for port 22 to become open
wait_for:
port: 22
host: '{{ item.instance.ipv4[0] }}'
search_regex: OpenSSH
delay: 10
connection: local
with_items: "{{ client_info.results }}"