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