Skip to content

Commit ac54a9f

Browse files
authored
Merge pull request #283 from tiewei/fix-env-json
Format env.json as JSON format
2 parents 636f414 + 27d1d9e commit ac54a9f

File tree

5 files changed

+160
-154
lines changed

5 files changed

+160
-154
lines changed

install/ansible/env.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
{
2-
"docker_version":"__DOCKER_VERSION__",
3-
"aci_gw_image":"contiv/aci-gw:__ACI_GW_VERSION__",
4-
"contiv_network_version":"__CONTIV_VERSION__",
5-
"env": "{}",
1+
{
2+
"docker_version": "__DOCKER_VERSION__",
3+
"aci_gw_image": "contiv/aci-gw:__ACI_GW_VERSION__",
4+
"contiv_network_version": "__CONTIV_VERSION__",
5+
"env": {},
66
"etcd_peers_group": "netplugin-master",
77
"service_vip": "__NETMASTER_IP__",
8-
"validate_certs": "no",
8+
"validate_certs": false,
99
"cluster_store": "__CLUSTER_STORE__",
1010
"auth_proxy_image": "contiv/auth_proxy:__API_PROXY_VERSION__",
11-
"docker_reset_container_state": "False",
12-
"docker_reset_image_state": "False",
13-
"etcd_cleanup_state": "False",
14-
"auth_proxy_local_install": "False",
15-
"contiv_network_local_install": "False",
16-
"vxlan_port": "4789",
11+
"docker_reset_container_state": __DOCKER_RESET_CONTAINER_STATE__,
12+
"docker_reset_image_state": __DOCKER_RESET_IMAGE_STATE__,
13+
"etcd_cleanup_state": __ETCD_CLEANUP_STATE__,
14+
"auth_proxy_local_install": __AUTH_PROXY_LOCAL_INSTALL__,
15+
"contiv_network_local_install": __CONTIV_NETWORK_LOCAL_INSTALL__,
16+
"vxlan_port": __VXLAN_PORT__,
1717
"netctl_url": "http://__NETMASTER_IP__:9999",
18-
"contiv_v2plugin_install": "False",
18+
"contiv_v2plugin_install": __CONTIV_V2PLUGIN_INSTALL__,
1919
"contiv_v2plugin_image": "contiv/v2plugin:__CONTIV_V2PLUGIN_VERSION__"
2020
}

install/ansible/install.sh

+52-49
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
set -euo pipefail
3+
set -xeuo pipefail
44

55
# This scripts runs in a container with ansible installed.
66
. ./install/ansible/install_defaults.sh
@@ -39,38 +39,38 @@ error_ret() {
3939

4040
while getopts ":n:a:im:d:v:ps:" opt; do
4141
case $opt in
42-
n)
43-
netmaster=$OPTARG
44-
;;
45-
a)
46-
ans_opts=$OPTARG
47-
;;
48-
i)
49-
install_scheduler=true
50-
;;
51-
m)
52-
contiv_network_mode=$OPTARG
53-
;;
54-
d)
55-
fwd_mode=$OPTARG
56-
;;
57-
v)
58-
aci_image=$OPTARG
59-
;;
60-
p)
61-
contiv_v2plugin_install=true
62-
;;
63-
s)
64-
cluster_store=$OPTARG
65-
install_etcd=false
66-
;;
67-
:)
68-
echo "An argument required for $OPTARG was not passed"
69-
usage
70-
;;
71-
?)
72-
usage
73-
;;
42+
n)
43+
netmaster=$OPTARG
44+
;;
45+
a)
46+
ans_opts=$OPTARG
47+
;;
48+
i)
49+
install_scheduler=true
50+
;;
51+
m)
52+
contiv_network_mode=$OPTARG
53+
;;
54+
d)
55+
fwd_mode=$OPTARG
56+
;;
57+
v)
58+
aci_image=$OPTARG
59+
;;
60+
p)
61+
contiv_v2plugin_install=true
62+
;;
63+
s)
64+
cluster_store=$OPTARG
65+
install_etcd=false
66+
;;
67+
:)
68+
echo "An argument required for $OPTARG was not passed"
69+
usage
70+
;;
71+
?)
72+
usage
73+
;;
7474
esac
7575
done
7676

@@ -128,23 +128,29 @@ if [ "$cluster_store" == "" ]; then
128128
cluster_store="etcd://localhost:2379"
129129
fi
130130

131-
sed -i.bak "s#.*service_vip.*#\"service_vip\":\"$service_vip\",#g" "$env_file"
132-
sed -i.bak "s#.*netctl_url.*#\"netctl_url\":\"http://$service_vip:9999\",#g" "$env_file"
133-
sed -i.bak "s#.*cluster_store.*#\"cluster_store\":\"$cluster_store\",#g" "$env_file"
131+
sed -i.bak 's#__NETMASTER_IP__#'"$service_vip"'#g' "$env_file"
132+
sed -i.bak 's#__CLUSTER_STORE__#'"$cluster_store"'#g' "$env_file"
133+
sed -i.bak 's#__DOCKER_RESET_CONTAINER_STATE__#false#g' "$env_file"
134+
sed -i.bak 's#__DOCKER_RESET_IMAGE_STATE__#false#g' "$env_file"
135+
sed -i.bak 's#__ETCD_CLEANUP_STATE__#false#g' "$env_file"
136+
sed -i.bak 's#__AUTH_PROXY_LOCAL_INSTALL__#false#g' "$env_file"
137+
sed -i.bak 's#__CONTIV_NETWORK_LOCAL_INSTALL__#false#g' "$env_file"
134138

135139
# Copy certs
136140
cp /var/contiv/cert.pem /ansible/roles/auth_proxy/files/
137141
cp /var/contiv/key.pem /ansible/roles/auth_proxy/files/
138142

139143
if [ "$aci_image" != "" ]; then
140-
sed -i.bak "s#.*aci_gw_image.*#\"aci_gw_image\":\"$aci_image\",#g" "$env_file"
144+
sed -i.bak 's#__ACI_GW_VERSION__#'"$aci_image"'#g' "$env_file"
141145
fi
142146
if [ "$contiv_v2plugin_install" == "true" ]; then
143-
sed -i.bak "s#.*vxlan_port.*#\"vxlan_port\":\"8472\",#g" "$env_file"
144-
sed -i.bak "s#.*contiv_v2plugin_install.*#\"contiv_v2plugin_install\":\"True\",#g" "$env_file"
147+
# docker uses 4789 port for container ingress network, uses 8472 by default to avoid conflicting
148+
# https://docs.docker.com/engine/swarm/ingress/
149+
sed -i.bak 's#__VXLAN_PORT__#8472#g' "$env_file"
150+
sed -i.bak 's#__CONTIV_V2PLUGIN_INSTALL__#true#g' "$env_file"
145151
else
146-
sed -i.bak "s#.*vxlan_port.*#\"vxlan_port\":\"4789\",#g" "$env_file"
147-
sed -i.bak "s#.*contiv_v2plugin_install.*#\"contiv_v2plugin_install\":\"False\",#g" "$env_file"
152+
sed -i.bak 's#__VXLAN_PORT__#4789#g' "$env_file"
153+
sed -i.bak 's#__CONTIV_V2PLUGIN_INSTALL__#false#g' "$env_file"
148154
fi
149155

150156
echo "Installing Contiv"
@@ -170,14 +176,11 @@ echo '- include: install_auth_proxy.yml' >>$ansible_path/install_plays.yml
170176
log_file_name="contiv_install_$(date -u +%m-%d-%Y.%H-%M-%S.UTC).log"
171177
log_file="/var/contiv/$log_file_name"
172178

173-
# Ansible needs unquoted booleans but we need quoted booleans for json parsing.
174-
# So remove quotes before sending to ansible and add them back after.
175-
sed -i.bak "s#\"True\"#True#gI" "$env_file"
176-
sed -i.bak "s#\"False\"#False#gI" "$env_file"
177-
ansible-playbook $ans_opts -i "$host_inventory" -e "$(cat $env_file)" $ansible_path/install_plays.yml | tee $log_file
178-
sed -i.bak "s#True#\"True\"#gI" "$env_file"
179-
sed -i.bak "s#False#\"False\"#gI" "$env_file"
180-
rm -rf "$env_file.bak*"
179+
echo "Ansible extra vars from env.json:"
180+
cat "$env_file"
181+
# run playbook
182+
ansible-playbook $ans_opts -i "$host_inventory" -e@"$env_file" $ansible_path/install_plays.yml | tee $log_file
183+
rm -rf "$env_file.bak"
181184

182185
unreachable=$(grep "PLAY RECAP" -A 9999 $log_file | awk -F "unreachable=" '{print $2}' | awk '{print $1}' | grep -v "0" | xargs)
183186
failed=$(grep "PLAY RECAP" -A 9999 $log_file | awk -F "failed=" '{print $2}' | awk '{print $1}' | grep -v "0" | xargs)

install/ansible/install_swarm.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Mandatory Options:
3434
-f string Configuration file (cfg.yml) listing the hostnames with the control and data interfaces and optionally ACI parameters
3535
-e string SSH key to connect to the hosts
3636
-u string SSH User
37-
-i Install the scheduler stack
37+
-i Install the scheduler stack
3838
-p Install v2plugin
3939
4040
Additional Options:
@@ -51,7 +51,7 @@ Additional parameters can also be updated in install/ansible/env.json file.
5151
5252
Examples:
5353
54-
1. Install Contiv with Docker Swarm on hosts specified by cfg.yml.
54+
1. Install Contiv with Docker Swarm on hosts specified by cfg.yml.
5555
./install/ansible/install_swarm.sh -f cfg.yml -e ~/ssh_key -u admin -i
5656
5757
2. Install Contiv on hosts specified by cfg.yml. Docker should be pre-installed on the hosts.

install/ansible/uninstall.sh

+56-55
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
set -euo pipefail
3+
set -xeuo pipefail
44
# This scripts runs in a container with ansible installed.
55
. ./install/ansible/install_defaults.sh
66

@@ -40,43 +40,43 @@ error_ret() {
4040

4141
while getopts ":n:a:ipm:d:v:rgs:" opt; do
4242
case $opt in
43-
n)
44-
netmaster=$OPTARG
45-
;;
46-
a)
47-
ans_opts=$OPTARG
48-
;;
49-
i)
50-
uninstall_scheduler=true
51-
;;
52-
p)
53-
uninstall_v2plugin=true
54-
;;
55-
m)
56-
contiv_network_mode=$OPTARG
57-
;;
58-
d)
59-
fwd_mode=$OPTARG
60-
;;
61-
v)
62-
aci_image=$OPTARG
63-
;;
64-
s)
65-
cluster_store=$OPTARG
66-
;;
67-
r)
68-
reset="true"
69-
;;
70-
g)
71-
reset_images="true"
72-
;;
73-
:)
74-
echo "An argument required for $OPTARG was not passed"
75-
usage
76-
;;
77-
?)
78-
usage
79-
;;
43+
n)
44+
netmaster=$OPTARG
45+
;;
46+
a)
47+
ans_opts=$OPTARG
48+
;;
49+
i)
50+
uninstall_scheduler=true
51+
;;
52+
p)
53+
uninstall_v2plugin=true
54+
;;
55+
m)
56+
contiv_network_mode=$OPTARG
57+
;;
58+
d)
59+
fwd_mode=$OPTARG
60+
;;
61+
v)
62+
aci_image=$OPTARG
63+
;;
64+
s)
65+
cluster_store=$OPTARG
66+
;;
67+
r)
68+
reset="true"
69+
;;
70+
g)
71+
reset_images="true"
72+
;;
73+
:)
74+
echo "An argument required for $OPTARG was not passed"
75+
usage
76+
;;
77+
?)
78+
usage
79+
;;
8080
esac
8181
done
8282

@@ -105,7 +105,7 @@ env_file=install/ansible/env.json
105105

106106
echo "Verifying ansible reachability"
107107
ansible all -vvv $ans_opts -i $host_inventory -m setup -a 'filter=ansible_distribution*' | tee $inventory_log
108-
if [ egrep 'FAIL|UNREACHABLE' $inventory_log > /dev/null ]; then
108+
if [ egrep 'FAIL|UNREACHABLE' $inventory_log ] >/dev/null; then
109109
echo "WARNING Some of the hosts are not accessible via passwordless SSH"
110110
echo " "
111111
echo "This means either the host is unreachable or passwordless SSH is not"
@@ -128,20 +128,24 @@ if [ "$cluster_store" == "" ]; then
128128
cluster_store="etcd://$service_vip:2379"
129129
fi
130130

131-
sed -i.bak "s#.*service_vip.*#\"service_vip\":\"$service_vip\",#g" "$env_file"
132-
sed -i.bak "s#.*cluster_store.*#\"cluster_store\":\"$cluster_store\",#g" "$env_file"
131+
sed -i.bak 's#__NETMASTER_IP__#'"$service_vip"'#g' "$env_file"
132+
sed -i.bak 's#__CLUSTER_STORE__#'"$cluster_store"'#g' "$env_file"
133133

134-
sed -i.bak "s/.*docker_reset_container_state.*/\"docker_reset_container_state\":$reset,/g" $env_file
135-
sed -i.bak "s/.*docker_reset_image_state.*/\"docker_reset_image_state\":$reset_images,/g" $env_file
136-
sed -i.bak "s/.*etcd_cleanup_state.*/\"etcd_cleanup_state\":$reset,/g" $env_file
134+
sed -i.bak 's#__DOCKER_RESET_CONTAINER_STATE__#'"$reset"'#g' "$env_file"
135+
sed -i.bak 's#__DOCKER_RESET_IMAGE_STATE__#'"$reset_images"'#g' "$env_file"
136+
sed -i.bak 's#__ETCD_CLEANUP_STATE__#'"$reset"'#g' "$env_file"
137+
sed -i.bak 's#__AUTH_PROXY_LOCAL_INSTALL__#false#g' "$env_file"
138+
sed -i.bak 's#__CONTIV_NETWORK_LOCAL_INSTALL__#false#g' "$env_file"
139+
sed -i.bak 's#__AUTH_PROXY_LOCAL_INSTALL__#false#g' "$env_file"
140+
sed -i.bak 's#__CONTIV_NETWORK_LOCAL_INSTALL__#false#g' "$env_file"
137141

138142
if [ "$aci_image" != "" ]; then
139-
sed -i.bak "s#.*aci_gw_image.*#\"aci_gw_image\":\"$aci_image\",#g" "$env_file"
143+
sed -i.bak 's#__ACI_GW_VERSION__#'"$aci_image"'#g' "$env_file"
140144
fi
141145
if [ "$uninstall_v2plugin" == "true" ]; then
142-
sed -i.bak "s#.*contiv_v2plugin_install.*#\"contiv_v2plugin_install\":\"True\",#g" "$env_file"
146+
sed -i.bak 's#__CONTIV_V2PLUGIN_INSTALL__#true#g' "$env_file"
143147
else
144-
sed -i.bak "s#.*contiv_v2plugin_install.*#\"contiv_v2plugin_install\":\"False\",#g" "$env_file"
148+
sed -i.bak 's#__CONTIV_V2PLUGIN_INSTALL__#false#g' "$env_file"
145149
fi
146150

147151
echo "Uninstalling Contiv"
@@ -163,14 +167,11 @@ fi
163167
log_file_name="contiv_uninstall_$(date -u +%m-%d-%Y.%H-%M-%S.UTC).log"
164168
log_file="/var/contiv/$log_file_name"
165169

166-
# Ansible needs unquoted booleans but we need quoted booleans for json parsing.
167-
# So remove quotes before sending to ansible and add them back after.
168-
sed -i.bak "s#\"True\"#True#gI" "$env_file"
169-
sed -i.bak "s#\"False\"#False#gI" "$env_file"
170-
ansible-playbook $ans_opts -i "$host_inventory" -e "$(cat $env_file)" $ansible_path/uninstall_plays.yml | tee $log_file
171-
sed -i.bak "s#True#\"True\"#gI" "$env_file"
172-
sed -i.bak "s#False#\"False\"#gI" "$env_file"
173-
rm -rf "$env_file.bak*"
170+
echo "Ansible extra vars from env.json:"
171+
cat "$env_file"
172+
ansible-playbook $ans_opts -i "$host_inventory" -e@"$env_file" $ansible_path/uninstall_plays.yml | tee $log_file
173+
174+
rm -rf "$env_file.bak"
174175

175176
unreachable=$(grep "PLAY RECAP" -A 9999 $log_file | awk -F "unreachable=" '{print $2}' | awk '{print $1}' | grep -v "0" | xargs)
176177
failed=$(grep "PLAY RECAP" -A 9999 $log_file | awk -F "failed=" '{print $2}' | awk '{print $1}' | grep -v "0" | xargs)

0 commit comments

Comments
 (0)