-
Notifications
You must be signed in to change notification settings - Fork 2
/
provision.yml
100 lines (91 loc) · 2.61 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# create galera linodes
- name: create galera linodes
hosts: localhost
vars_files:
- group_vars/galera/vars
- group_vars/galera/secret_vars
vars:
count: 3
tasks:
- name: creating galera linodes
linode.cloud.instance:
label: '{{ galera_prefix }}{{ item }}'
api_token: '{{ token }}'
type: '{{ type }}'
region: '{{ region }}'
image: '{{ image }}'
root_pass: '{{ root_pass }}'
authorized_keys: '{{ ssh_keys }}'
private_ip: true
group: '{{ group }}'
tags: '{{ linode_tags }}'
state: present
register: linode
with_sequence: count='{{count}}'
- name: Get info about an instance by label
linode.cloud.instance_info:
api_token: '{{ token }}'
label: '{{ galera_prefix }}{{ item }}'
register: info
with_sequence: count='{{count}}'
- name: set facts
set_fact:
# hostnames
galera1: '{{ info.results.0.instance.label }}'
galera2: '{{ info.results.1.instance.label }}'
galera3: '{{ info.results.2.instance.label }}'
# public ips
galera_ip1: '{{ info.results.0.instance.ipv4[0] }}'
galera_ip2: '{{ info.results.1.instance.ipv4[0] }}'
galera_ip3: '{{ info.results.2.instance.ipv4[0] }}'
# private ips
galera_priv1: '{{ info.results.0.instance.ipv4[1] }}'
galera_priv2: '{{ info.results.1.instance.ipv4[1] }}'
galera_priv3: '{{ info.results.2.instance.ipv4[1] }}'
- name: test connectivity
ping: '{{ item }}'
with_items:
- '{{ galera_ip1 }}'
- '{{ galera_ip2 }}'
- '{{ galera_ip3 }}'
- name: update group_vars
blockinfile:
path: ./group_vars/galera/vars
marker: "# {mark} INSTANCE VARS"
block: |
# hostnames
host1: {{ galera1 }}
host2: {{ galera2 }}
host3: {{ galera3 }}
# private ips
priv_ip1: {{ galera_priv1 }}
priv_ip2: {{ galera_priv2 }}
priv_ip3: {{ galera_priv3 }}
- name: update inventory
blockinfile:
path: ./hosts
marker: "# {mark} GALERA LINODES"
block: |
[galera_servers]
{{ galera_ip1 }}
{{ galera_ip2 }}
{{ galera_ip3 }}
- name: update in-memory inventory
add_host:
name: '{{ item }}'
groups: galera_servers
with_items:
- '{{ galera_ip1 }}'
- '{{ galera_ip2 }}'
- '{{ galera_ip3 }}'
- name: wait for port 22 to become open
wait_for:
port: 22
host: '{{ item }}'
search_regex: OpenSSH
delay: 10
connection: local
with_items:
- '{{ galera_ip1 }}'
- '{{ galera_ip2 }}'
- '{{ galera_ip3 }}'