-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_logstash_gce.py
82 lines (71 loc) · 2.83 KB
/
gen_logstash_gce.py
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
from package.generate_conf import setup_configurations, merge_and_delete_ini_files
from package.execute_command import run_ansible_playbook
import sys
if len(sys.argv) != 2:
print('didn\'t get playbook path')
sys.exit(1)
playbook_path = sys.argv[1]
default_dir = 'playbook'
project_id = 'project-id'
region = 'asia-east1'
group_vars = {
'project_id' : project_id,
'region' : region,
}
logstash_inventory_vars = {
'group' : 'logstash',
'hosts' :
[
{"hostname": "logstash", "IP": "10.140.0.22", "zone": "asia-east1-b"},
]
}
master_inventory_vars = {
'group' : 'elastic_master',
'hosts' :
[
{"hostname": "master", "IP": "10.140.0.28", "zone": "asia-east1-b", "node_name": "master", "node_role": "hot"},
]
}
slave_inventory_vars = {
'group' : 'elastic_slave',
'hosts' :
[
{"hostname": "slave2", "IP": "10.140.0.30", "zone": "asia-east1-b", "node_name": "slave2", "node_role": "warm"},
{"hostname": "slave1", "IP": "10.140.0.29", "zone": "asia-east1-b", "node_name": "slave1", "node_role": "warm"},
]
}
instance_vars = {
'machine_type' : 'e2-medium',
'boot_disk_size' : '20',
'boot_disk_type' : 'pd-standard',
'scopes' : 'default',
'subnet' : 'projects/project-id/regions/asia-east1/subnetworks/asia-east1',
'labels': {
'env': 'dev',
},
'tags': ['dev', 'test'],
}
elasticsearch_vars = {
'cluster_name' : 'elk',
'master_ip' : '10.140.0.28',
'ilm_policy' : 'elk',
'elastic_port' : 9200,
}
monitor_vars = {
'enabled_node_exporter': 'true',
}
configurations = {
'group_vars' : (group_vars, 'group_vars/all/env.j2', 'group_vars/all/env.yml'),
'logstash_inventory' : (logstash_inventory_vars, 'inventory/inventory.j2', 'inventory/logstash_inventory.yml'),
'master_inventory' : (master_inventory_vars, 'inventory/inventory.j2', 'inventory/master_inventory.yml'),
'slave_inventory' : (slave_inventory_vars, 'inventory/inventory.j2', 'inventory/slave_inventory.yml'),
'instance' : (instance_vars, 'vars/instance/instance_var.j2', 'vars/instance/vars.yml'),
'elasticsearch' : (elasticsearch_vars, 'vars/elasticsearch/elasticsearch_var.j2', 'vars/elasticsearch/vars.yml'),
'monitor' : (monitor_vars, 'vars/monitor/monitor_var.j2', 'vars/monitor/vars.yml')
}
setup_configurations(configurations)
inventory_list = ['logstash_inventory','master_inventory','slave_inventory']
file_list = [configurations[config][2] for config in inventory_list]
inventory_path = f'{default_dir}/inventory/inventory.yml'
merge_and_delete_ini_files(file_list, inventory_path)
run_ansible_playbook(inventory_path, playbook_path)