fix yamllint verify fail
[releng.git] / utils / test / testapi / update / playbook-update.sh
1 #!/bin/bash
2
3 #
4 # Author: Serena Feng (feng.xiaoewi@zte.com.cn)
5 # Update testapi on remote server using ansible playbook automatically
6 #
7 #
8 # All rights reserved. This program and the accompanying materials
9 # are made available under the terms of the Apache License, Version 2.0
10 # which accompanies this distribution, and is available at
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13
14 set -e
15
16 usage="Script to trigger update automatically.
17
18 usage:
19     bash $(basename "$0") [-h|--help] [-h <host>] [-u username] [-i identityfile] [-e|--execute]
20
21 where:
22     -h|--help           show this help text
23     -r|--remote         remote server
24     -u|--user           ssh username used to access to remote server
25     -i|--identity       ssh PublicKey file used to access to remote server
26     -e|--execute        execute update, if not set just check the ansible connectivity"
27
28 remote=testresults.opnfv.org
29 user=root
30 identity=~/.ssh/id_rsa
31 hosts=./hosts
32 execute=false
33
34 # Parse parameters
35 while [[ $# > 0 ]]
36     do
37     key="$1"
38     case $key in
39         -h|--help)
40             echo "$usage"
41             exit 0
42             shift
43         ;;
44         -r|--remote)
45             remote="$2"
46             shift
47         ;;
48         -u|--user)
49             user="$2"
50             shift
51         ;;
52         -i|--identity)
53             identity="$2"
54             shift
55         ;;
56         -e|--execute)
57             execute=true
58         ;;
59         *)
60             echo "unknown option"
61             exit 1
62         ;;
63     esac
64     shift # past argument or value
65 done
66
67 echo $remote > $hosts
68
69 echo "add authentication"
70 ssh-add $identity
71
72 echo "test ansible connectivity"
73 ansible -i ./hosts $remote -m ping -u $user
74
75 echo "test playbook connectivity"
76 ansible-playbook -i $hosts test.yml -e "host=$remote user=$user"
77
78 if [ $execute == true ]; then
79     echo "do update"
80     ansible-playbook -i $hosts update.yml -e "host=$remote \
81     user=$user \
82     port=8082 \
83     image=opnfv/testapi \
84     update_path=/home/$user/testapi \
85     mongodb_url=mongodb://172.17.0.1:27017 \
86     swagger_url=http://testresults.opnfv.org/test"
87 fi
88
89 rm -fr $hosts
90 ssh-agent -k