forked from anukat2015/datal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
executable file
·89 lines (67 loc) · 2.14 KB
/
Copy pathinstall.py
File metadata and controls
executable file
·89 lines (67 loc) · 2.14 KB
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
#! /usr/bin/python
import os
import urllib2
from subprocess import call
SALT_HIGHSTATE_COMMAND = 'salt-call state.highstate'
SALT_INSTALLER_COMMAND = "sudo sh /tmp/bootstrap_salt.sh git develop"
SALT_DOWNLOAD_COMMAND = "curl -o /tmp/bootstrap_salt.sh -L https://bootstrap.saltstack.com"
SALT_RESTART_COMMAND = "service salt-minion restart"
python_git_pkg = 'python-git'
minion_file = '/etc/salt/minion'
MINION_FILE_CONTENT = """
file_client: local
fileserver_backend:
- git
gitfs_base: master
gitfs_remotes:
- https://github.com/Junar/datal-formula.git
pillar_roots:
base:
- /srv/salt/pillar
"""
MINION_PILLAR_DIR = '/srv/salt/pillar'
MINION_PILLAR_TOP_FILE_CONTENT = """
base:
'*':
- general
{% if salt['file.file_exists']('/srv/salt/pillar/local.sls') %}
- local
{% endif %}
"""
def install_salt():
print("Instalando SaltStack / Installing SaltStack")
call(SALT_DOWNLOAD_COMMAND, shell=True)
call(SALT_INSTALLER_COMMAND, shell=True)
def restart_salt():
print("Reiniciando SaltStack / Restarting SaltStack")
return call(SALT_RESTART_COMMAND, shell=True)
def install_deps():
print("Instalando dependencias / Installing deps")
return call('apt-get install {} -y'.format(python_git_pkg), shell=True)
def salt_configuration():
print("Configurando SaltStack / Setting up SaltStack")
# Minion file content
f = open(minion_file, 'w')
f.writelines(MINION_FILE_CONTENT)
f.close()
# Pillar directory
if not os.path.exists(MINION_PILLAR_DIR):
os.makedirs(MINION_PILLAR_DIR)
# Get Pillars
fname = '{}/general.sls'.format(MINION_PILLAR_DIR)
url = 'https://raw.githubusercontent.com/Junar/datal-formula/master/pillar.example'
response = urllib2.urlopen(url)
content = response.read()
open(fname, 'w').write(content)
# Minion pillar top file content
f = open(MINION_PILLAR_DIR + '/top.sls', 'w')
f.writelines(MINION_PILLAR_TOP_FILE_CONTENT)
f.close()
def run_highstate():
print("Instalando Datal / Installing Datal")
return call(SALT_HIGHSTATE_COMMAND, shell=True)
install_salt()
install_deps()
salt_configuration()
restart_salt()
run_highstate()