Add ansible scripts to deploy Kubernetes
[yardstick.git] / tools / kube-setup-one-node.sh
1 #!/usr/bin/env bash
2 # Copyright (c) 2018-2019 Intel Corporation.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 proxy_vars=(http_proxy https_proxy ftp_proxy no_proxy)
17 # get proxy environment values from /etc/environment if not set
18 for proxy_var in ${proxy_vars[@]}
19 do
20     env_proxy=$(sed -ne "s/^$proxy_var=[\"\']\(.*\)[\"\']/\1/p" /etc/environment)
21     if [[ -z ${!proxy_var} ]] && [[ ! -z ${env_proxy} ]]; then
22         export ${proxy_var}=${env_proxy}
23     fi
24 done
25 # add proxy configuration into proxy file
26 add_extra_env=false
27 echo "proxy_env:" > /tmp/proxy.yml
28 for proxy_var in ${proxy_vars[@]}
29 do
30     if [[ ! -z ${!proxy_var} ]]; then
31         echo "  ${proxy_var}: ${!proxy_var}" >> /tmp/proxy.yml
32         add_extra_env=true
33     fi
34 done
35 # add extra arguments file if needed
36 if ${add_extra_env}; then
37     extra_args="${extra_args} -e @/tmp/proxy.yml "
38 fi
39
40 ANSIBLE_SCRIPTS="${0%/*}/../ansible"
41
42 cd ${ANSIBLE_SCRIPTS} && \
43 ansible-playbook \
44          ${extra_args} -i kube-inventory.ini deploy_kube.yml