-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
179 lines (141 loc) · 6.02 KB
/
bootstrap.sh
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# init
if [ "$1" = "init" ]; then
echo "Enter the database root password (admin):"
read semaphore_db_admin_password
echo "Enter the database password for the application (semaphore):"
read semaphore_db_auth_password
echo "Enter the password for the default application user (semaphore<root@localhost>):"
read semaphore_config_auth_password
echo "Enter the password for the account that will execute the application service (semaphore):"
read semaphore_service_user_password
echo "Enter your ansible vault password (/var/lib/semaphore/.vpf):"
read semaphore_ansible_cfg_vault_password
cat > vars.json <<EOL
{
"semaphore_version": "2.3.0",
"semaphore_port": 3000,
"semaphore_service_user_name": "semaphore",
"semaphore_service_user_password": "$semaphore_service_user_password", # required
"semaphore_db_admin_home": "/root",
"semaphore_db_admin_user": "admin",
"semaphore_db_admin_password": "$semaphore_db_admin_password", # required
"semaphore_db_name": "semaphore",
"semaphore_db_auth_user": "semaphore",
"semaphore_db_auth_password": "$semaphore_db_auth_password", # required
"semaphore_db_auth_privileges": "*.*:ALL",
"semaphore_config_data_dir": "/var/lib/semaphore",
"semaphore_config_log_path": "/var/log/semaphore",
"semaphore_config_auth_name": "Admin",
"semaphore_config_auth_email": "root@localhost",
"semaphore_config_auth_username": "admin",
"semaphore_config_auth_password": "$semaphore_config_auth_password", # required
"semaphore_config_email_alerts_enable": "no",
"semaphore_config_email_alerts_server": "localhost",
"semaphore_config_email_alerts_port": 25,
"semaphore_config_email_alerts_sender": "semaphore@localhost",
"semaphore_config_telegram_alerts_enable": "no",
"semaphore_config_telegram_alerts_bot_token": "",
"semaphore_config_telegram_alerts_chat_id": "",
"semaphore_config_web_root": "http://$HOSTNAME:3000/", # used in generating urls in alerts
"semaphore_config_ldap_enable": "no",
"semaphore_config_ldap_server": "localhost",
"semaphore_config_ldap_port": 389,
"semaphore_config_ldap_use_tls": "no",
"semaphore_config_ldap_bind_dn": "cn=user,ou=users,dc=example.tld",
"semaphore_config_ldap_bind_password": "pa55w0rd",
"semaphore_config_ldap_search_dn": "ou=users,dc=example.tld",
"semaphore_config_ldap_search_filter": "(uid=%s)",
"semaphore_config_ldap_mapping_dn_field": "dn",
"semaphore_config_ldap_mapping_username_field": "uid",
"semaphore_config_ldap_mapping_fullname_field": "cn",
"semaphore_config_ldap_mapping_email_field": "mail",
"semaphore_ansible_cfg_host_key_checking": "False",
"semaphore_ansible_cfg_ansible_managed": "DO NOT MODIFY by hand. This file is under control of Ansible on {host}.",
"semaphore_ansible_cfg_vault_password": "$semaphore_ansible_cfg_vault_password",
"semaphore_ansible_cfg_vault_password_file": "/var/lib/semaphore/.vpf",
}
EOL
cat > playbook.yml <<EOL
---
- hosts: 127.0.0.1
connection: local
become: yes
vars:
mariadb_group_users:
- name: '{{ semaphore_db_auth_user }}'
password: '{{ semaphore_db_auth_password }}'
priv: '*.*:ALL'
hosts:
- localhost
- 127.0.0.1
mariadb_admin_home: '{{ semaphore_db_admin_home }}'
mariadb_admin_user: '{{ semaphore_db_admin_user }}'
mariadb_admin_password: '{{ semaphore_db_admin_password }}'
logrotate_conf_scripts:
- name: semaphore
path: /var/log/semaphore/*.log
options:
- rotate 14
- daily
- compress
- delaycompress
- sharedscripts
- missingok
postrotate:
- /usr/sbin/service semaphore restart
configure_ansible_vault_password: '{{ semaphore_ansible_cfg_vault_password}}'
configure_ansible_vault_password_file:
path: '{{ semaphore_ansible_cfg_vault_password_file }}'
owner: 'root'
group: '{{ semaphore_service_user_name }}'
permissions: '0640'
configure_ansible_config_items:
defaults:
- { name: "host_key_checking", value: "{{ semaphore_ansible_cfg_host_key_checking }}" }
- { name: "ansible_managed", value: "DO NOT MODIFY by hand. This file is under control of Ansible on {host}." }
- { name: "vault_password_file", value: "{{ semaphore_ansible_cfg_vault_password_file }}" }
roles:
- thedumbtechguy.mariadb
- thedumbtechguy.semaphore
- thedumbtechguy.logrotate
- thedumbtechguy.configure-ansible
EOL
echo "Init complete. You can customize the variables by updating './vars.json'."
fi
# execute
if [ "$1" = "execute" ]; then
if [ ! -f vars.json ] || [ ! -f playbook.yml ]; then
echo "Please run 'init' first!"
elif ["$(whoami)" == "root"]; then
echo "Please run as root/sudo"
exit 1
elif [ ! -f .g ]; then
echo "Installing ansible and its dependencies"
apt-get -y install software-properties-common &&
apt-get -y install python-software-properties &&
apt-add-repository -y ppa:ansible/ansible &&
apt-get -y update &&
apt-get -y install ansible &&
ansible-galaxy install thedumbtechguy.mariadb &&
ansible-galaxy install thedumbtechguy.semaphore &&
ansible-galaxy install thedumbtechguy.logrotate &&
ansible-galaxy install thedumbtechguy.configure-ansible &&
touch .g
fi
if [ ! -f .g ]; then
echo "Dependencies not satisfied"
exit 1
else
echo "Executing playbook"
ansible-playbook playbook.yml --extra-vars "@vars.json"
fi
fi
# help
if [ -z "${1+present}" ] || [ "$1" = "help" ] || [ "$1" = "h" ]; then
echo "Usage: sudo sh bootstrap.sh options
Options:
- init initialize required files
You can customize the setup by modifying the generated 'vars.json'
Running this command again will generating fresh files.
- execute: execute bootstrapping tasks"
fi