-
Notifications
You must be signed in to change notification settings - Fork 56
/
install_swarm.sh
executable file
·177 lines (151 loc) · 4.61 KB
/
install_swarm.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
#!/bin/bash
set -euo pipefail
# This is the installation script for Contiv.
. ./install/ansible/install_defaults.sh
# Ansible options. By default, this specifies a private key to be used and the vagrant user
ans_opts=""
ans_user="root"
ans_key=$src_conf_path/insecure_private_key
install_scheduler=""
netmaster=""
v2plugin_param=""
contiv_v2plugin_install=""
# Check for docker
if ! docker version >/dev/null 2>&1; then
echo "docker not found or is not running."
echo "Please ensure docker is installed and running before retrying."
exit 1
fi
usage() {
cat <<EOF
Contiv Installer for Docker/Swarm based setups.
Installer:
Usage: ./install/ansible/install_swarm.sh OPTIONS
Mandatory Options:
-f string Configuration file (cfg.yml) listing the hostnames with the control and data interfaces and optionally ACI parameters
-e string SSH key to connect to the hosts
-u string SSH User
-i Install the scheduler stack
-p Install v2plugin
Additional Options:
-m string Network Mode for the Contiv installation (“standalone” or “aci”). Default mode is “standalone” and should be used for non ACI-based setups
-d string Forwarding mode (“routing” or “bridge”). Default mode is “bridge”
-c string
-k string
-a string Additonal ansible arguments such as "-v --ssh-common-args=\"-o ProxyCommand='nc -x 192.168.2.1 %h %p'\""
Advanced Options:
-v string ACI Image (default is contiv/aci-gw:latest). Use this to specify a specific version of the ACI Image.
-n string DNS name/IP address of the host to be used as the net master service VIP. This must be a host present in the cfg.yml file.
-s string URL of the cluster store to be used (for example etcd://etcd master or netmaster IP:2379)
Additional parameters can also be updated in install/ansible/env.json file.
Examples:
1. Install Contiv with Docker Swarm on hosts specified by cfg.yml.
./install/ansible/install_swarm.sh -f cfg.yml -e ~/ssh_key -u admin -i
2. Install Contiv on hosts specified by cfg.yml. Docker should be pre-installed on the hosts.
./install/ansible/install_swarm.sh -f cfg.yml -e ~/ssh_key -u admin
3. Install Contiv with Docker Swarm on hosts specified by cfg.yml in ACI mode.
./install/ansible/install_swarm.sh -f cfg.yml -e ~/ssh_key -u admin -i -m aci
4. Install Contiv with Docker Swarm on hosts specified by cfg.yml in ACI mode, using routing as the forwarding mode.
./install/ansible/install_swarm.sh -f cfg.yml -e ~/ssh_key -u admin -i -m aci -d routing
EOF
exit 1
}
# Create the config folder to be shared with the install container.
mkdir -p "$src_conf_path"
cluster_param=""
while getopts ":f:n:a:e:ipm:d:v:u:c:k:s:" opt; do
case $opt in
f)
cp "$OPTARG" "$host_contiv_config"
;;
n)
netmaster=$OPTARG
;;
a)
ans_opts="$OPTARG"
;;
e)
ans_key=$OPTARG
;;
u)
ans_user=$OPTARG
;;
m)
contiv_network_mode=$OPTARG
;;
d)
fwd_mode=$OPTARG
;;
v)
aci_image=$OPTARG
;;
s)
cluster_param="-s $OPTARG"
;;
i)
install_scheduler="-i"
;;
p)
v2plugin_param="-p"
;;
c)
cp "$OPTARG" "$host_tls_cert"
;;
k)
cp "$OPTARG" "$host_tls_key"
;;
:)
echo "An argument required for $OPTARG was not passed"
usage
;;
?)
usage
;;
esac
done
if [[ ! -f $host_contiv_config ]]; then
echo "Host configuration file missing"
usage
fi
if [ "$netmaster" != "" ]; then
netmaster_param="-n $netmaster"
else
netmaster_param=""
fi
if [ "$aci_image" != "" ]; then
aci_param="-v $aci_image"
else
aci_param=""
fi
# Copy the key to config folder
if [[ -f $ans_key ]]; then
cp "$ans_key" "$host_ans_key"
fi
if [ "$ans_opts" == "" ]; then
ans_opts="--private-key $def_ans_key -u $ans_user"
else
ans_opts+=" --private-key $def_ans_key -u $ans_user"
fi
# Generate SSL certs for auth proxy
if [[ ! -f "$host_tls_cert" || ! -f "$host_tls_key" ]]; then
echo "Generating local certs for Contiv Proxy"
openssl genrsa -out "$host_tls_key" 2048 >/dev/null 2>&1
openssl req -new -x509 -sha256 -days 3650 \
-key "$host_tls_key" \
-out "$host_tls_cert" \
-subj "/C=US/ST=CA/L=San Jose/O=CPSG/OU=IT Department/CN=auth-local.cisco.com"
fi
echo "Starting the installer container"
image_name="__CONTIV_INSTALL_VERSION__"
mounts[0]="-v"
mounts[1]="$(pwd)/install:/install:Z"
mounts[2]="-v"
mounts[3]="$(pwd)/ansible:/ansible:Z"
mounts[4]="-v"
mounts[5]="$src_conf_path:$container_conf_path:Z"
mounts[6]="-v"
mounts[7]="$(pwd)/contiv_cache:/var/contiv_cache:Z"
set -x
docker run --rm --net=host "${mounts[@]}" $image_name ./install/ansible/install.sh \
$netmaster_param -a "$ans_opts" $install_scheduler -m $contiv_network_mode \
-d $fwd_mode $aci_param $cluster_param $v2plugin_param