summaryrefslogtreecommitdiffstats
path: root/prototypes/openstack-ansible/scripts/osa_deploy.sh
blob: 79625d211d58b63710f969e33f2e1af8cc52b25c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash

export OSA_PATH=/opt/openstack-ansible
export LOG_PATH=$OSA_PATH/log
export PLAYBOOK_PATH=$OSA_PATH/playbooks
export OSA_BRANCH=${OSA_BRANCH:-"master"}
JUMPHOST_IP="192.168.122.2"

sudo /bin/rm -rf $LOG_PATH
sudo /bin/mkdir -p $LOG_PATH
sudo /bin/cp /root/.ssh/id_rsa.pub ../file/authorized_keys
sudo echo -e '\n'>>../file/authorized_keys

cd ../playbooks/
# this will prepare the jump host
# git clone the Openstack-Ansible, bootstrap and configure network
sudo ansible-playbook -i inventory jumphost_configuration.yml -vvv

# this will prepare the target host
# such as configure network and NFS
sudo ansible-playbook -i inventory targethost_configuration.yml

# using OpenStack-Ansible deploy the OpenStack

echo "set UP Host !"
sudo /bin/sh -c "ssh root@$JUMPHOST_IP openstack-ansible \
     $PLAYBOOK_PATH/setup-hosts.yml" | \
     tee $LOG_PATH/setup-host.log

#check the result of openstack-ansible setup-hosts.yml
#if failed, exit with exit code 1
grep "failed=1" $LOG_PATH/setup-host.log>/dev/null \
  || grep "unreachable=1" $LOG_PATH/setup-host.log>/dev/null
if [ $? -eq 0 ]; then
    echo "failed setup host!"
    exit 1
else
    echo "setup host successfully!"
fi

echo "Set UP Infrastructure !"
sudo /bin/sh -c "ssh root@$JUMPHOST_IP openstack-ansible \
     $PLAYBOOK_PATH/setup-infrastructure.yml" | \
     tee $LOG_PATH/setup-infrastructure.log

grep "failed=1" $LOG_PATH/setup-infrastructure.log>/dev/null \
  || grep "unreachable=1" $LOG_PATH/setup-infrastructure.log>/dev/null
if [ $? -eq 0 ]; then
    echo "failed setup infrastructure!"
    exit 1
else
    echo "setup infrastructure successfully!"
fi

sudo /bin/sh -c "ssh root@$JUMPHOST_IP ansible -i $PLAYBOOK_PATH/inventory/ \
           galera_container -m shell \
           -a "mysql -h localhost -e 'show status like \"%wsrep_cluster_%\";'"" \
           | tee $LOG_PATH/galera.log

grep "FAILED" $LOG_PATH/galera.log>/dev/null
if [ $? -eq 0 ]; then
    echo "failed verify the database cluster!"
    exit 1
else
    echo "verify the database cluster successfully!"
fi

echo "Set UP OpenStack !"
sudo /bin/sh -c "ssh root@$JUMPHOST_IP openstack-ansible \
     $PLAYBOOK_PATH/setup-openstack.yml" | \
     tee $LOG_PATH/setup-openstack.log

grep "failed=1" $LOG_PATH/setup-openstack.log>/dev/null \
  || grep "unreachable=1" $LOG_PATH/setup-openstack.log>/dev/null
if [ $? -eq 0 ]; then
   echo "failed setup openstack!"
   exit 1
else
   echo "OpenStack successfully deployed!"
   exit 0
fi