Read OSA_BRANCH from an env var
[releng.git] / prototypes / openstack-ansible / scripts / osa_deploy.sh
1 #!/bin/bash
2
3 export OSA_PATH=/opt/openstack-ansible
4 export LOG_PATH=$OSA_PATH/log
5 export PLAYBOOK_PATH=$OSA_PATH/playbooks
6 export OSA_BRANCH=${OSA_BRANCH:-"master"}
7 JUMPHOST_IP="192.168.122.2"
8
9 sudo /bin/rm -rf $LOG_PATH
10 sudo /bin/mkdir -p $LOG_PATH
11 sudo /bin/cp /root/.ssh/id_rsa.pub ../file/authorized_keys
12 sudo echo -e '\n'>>../file/authorized_keys
13
14 cd ../playbooks/
15 # this will prepare the jump host
16 # git clone the Openstack-Ansible, bootstrap and configure network
17 sudo ansible-playbook -i inventory jumphost_configuration.yml -vvv
18
19 # this will prepare the target host
20 # such as configure network and NFS
21 sudo ansible-playbook -i inventory targethost_configuration.yml
22
23 # using OpenStack-Ansible deploy the OpenStack
24
25 echo "set UP Host !"
26 sudo /bin/sh -c "ssh root@$JUMPHOST_IP openstack-ansible \
27      $PLAYBOOK_PATH/setup-hosts.yml" | \
28      tee $LOG_PATH/setup-host.log
29
30 #check the result of openstack-ansible setup-hosts.yml
31 #if failed, exit with exit code 1
32 grep "failed=1" $LOG_PATH/setup-host.log>/dev/null \
33   || grep "unreachable=1" $LOG_PATH/setup-host.log>/dev/null
34 if [ $? -eq 0 ]; then
35     echo "failed setup host!"
36     exit 1
37 else
38     echo "setup host successfully!"
39 fi
40
41 echo "Set UP Infrastructure !"
42 sudo /bin/sh -c "ssh root@$JUMPHOST_IP openstack-ansible \
43      $PLAYBOOK_PATH/setup-infrastructure.yml" | \
44      tee $LOG_PATH/setup-infrastructure.log
45
46 grep "failed=1" $LOG_PATH/setup-infrastructure.log>/dev/null \
47   || grep "unreachable=1" $LOG_PATH/setup-infrastructure.log>/dev/null
48 if [ $? -eq 0 ]; then
49     echo "failed setup infrastructure!"
50     exit 1
51 else
52     echo "setup infrastructure successfully!"
53 fi
54
55 sudo /bin/sh -c "ssh root@$JUMPHOST_IP ansible -i $PLAYBOOK_PATH/inventory/ \
56            galera_container -m shell \
57            -a "mysql -h localhost -e 'show status like \"%wsrep_cluster_%\";'"" \
58            | tee $LOG_PATH/galera.log
59
60 grep "FAILED" $LOG_PATH/galera.log>/dev/null
61 if [ $? -eq 0 ]; then
62     echo "failed verify the database cluster!"
63     exit 1
64 else
65     echo "verify the database cluster successfully!"
66 fi
67
68 echo "Set UP OpenStack !"
69 sudo /bin/sh -c "ssh root@$JUMPHOST_IP openstack-ansible \
70      $PLAYBOOK_PATH/setup-openstack.yml" | \
71      tee $LOG_PATH/setup-openstack.log
72
73 grep "failed=1" $LOG_PATH/setup-openstack.log>/dev/null \
74   || grep "unreachable=1" $LOG_PATH/setup-openstack.log>/dev/null
75 if [ $? -eq 0 ]; then
76    echo "failed setup openstack!"
77    exit 1
78 else
79    echo "OpenStack successfully deployed!"
80    exit 0
81 fi