1
1
#! /bin/sh
2
2
3
- set -euo pipefail
3
+ set -xeuo pipefail
4
4
# This scripts runs in a container with ansible installed.
5
5
. ./install/ansible/install_defaults.sh
6
6
@@ -40,43 +40,43 @@ error_ret() {
40
40
41
41
while getopts " :n:a:ipm:d:v:rgs:" opt; do
42
42
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
+ ;;
80
80
esac
81
81
done
82
82
@@ -105,7 +105,7 @@ env_file=install/ansible/env.json
105
105
106
106
echo " Verifying ansible reachability"
107
107
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
109
109
echo " WARNING Some of the hosts are not accessible via passwordless SSH"
110
110
echo " "
111
111
echo " This means either the host is unreachable or passwordless SSH is not"
@@ -128,20 +128,24 @@ if [ "$cluster_store" == "" ]; then
128
128
cluster_store=" etcd://$service_vip :2379"
129
129
fi
130
130
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 "
133
133
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 "
137
141
138
142
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 "
140
144
fi
141
145
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 "
143
147
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 "
145
149
fi
146
150
147
151
echo " Uninstalling Contiv"
163
167
log_file_name=" contiv_uninstall_$( date -u +%m-%d-%Y.%H-%M-%S.UTC) .log"
164
168
log_file=" /var/contiv/$log_file_name "
165
169
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"
174
175
175
176
unreachable=$( grep " PLAY RECAP" -A 9999 $log_file | awk -F " unreachable=" ' {print $2}' | awk ' {print $1}' | grep -v " 0" | xargs)
176
177
failed=$( grep " PLAY RECAP" -A 9999 $log_file | awk -F " failed=" ' {print $2}' | awk ' {print $1}' | grep -v " 0" | xargs)
0 commit comments