Merge "Revert "Specify cell0 db creation""
[apex-tripleo-heat-templates.git] / extraconfig / post_deploy / undercloud_post.sh
1 #!/bin/bash
2 set -eux
3
4 ln -sf /etc/puppet/hiera.yaml /etc/hiera.yaml
5
6
7 # WRITE OUT STACKRC
8 if [ ! -e /root/stackrc ]; then
9     touch /root/stackrc
10     chmod 0600 /root/stackrc
11
12 cat >> /root/stackrc <<-EOF_CAT
13 export OS_PASSWORD=$admin_password
14 export OS_AUTH_URL=$auth_url
15 export OS_USERNAME=admin
16 export OS_TENANT_NAME=admin
17 export COMPUTE_API_VERSION=1.1
18 export NOVA_VERSION=1.1
19 export OS_BAREMETAL_API_VERSION=1.15
20 export OS_NO_CACHE=True
21 export OS_CLOUDNAME=undercloud
22 EOF_CAT
23
24     if [ -n "$ssl_certificate" ]; then
25 cat >> /root/stackrc <<-EOF_CAT
26 export PYTHONWARNINGS="ignore:Certificate has no, ignore:A true SSLContext object is not available"
27 EOF_CAT
28     fi
29 fi
30
31 source /root/stackrc
32
33 if [ ! -f /root/.ssh/authorized_keys ]; then
34     sudo mkdir -p /root/.ssh
35     sudo chmod 7000 /root/.ssh/
36     sudo touch /root/.ssh/authorized_keys
37     sudo chmod 600 /root/.ssh/authorized_keys
38 fi
39
40 if [ ! -f /root/.ssh/id_rsa ]; then
41     ssh-keygen -b 1024 -N '' -f /root/.ssh/id_rsa
42 fi
43
44 if ! grep "$(cat /root/.ssh/id_rsa.pub)" /root/.ssh/authorized_keys; then
45     cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
46 fi
47
48 PHYSICAL_NETWORK=ctlplane
49
50 ctlplane_id=$(openstack network list -f csv -c ID -c Name --quote none | tail -n +2 | grep ctlplane | cut -d, -f1)
51 subnet_ids=$(openstack subnet list -f csv -c ID --quote none | tail -n +2)
52 subnet_id=
53
54 for subnet_id in $subnet_ids; do
55     network_id=$(openstack subnet show -f value -c network_id $subnet_id)
56     if [ "$network_id" = "$ctlplane_id" ]; then
57         break
58     fi
59 done
60
61 net_create=1
62 if [ -n "$subnet_id" ]; then
63     cidr=$(openstack subnet show $subnet_id -f value -c cidr)
64     if [ "$cidr" = "$undercloud_network_cidr" ]; then
65         net_create=0
66     else
67         echo "New cidr $undercloud_network_cidr does not equal old cidr $cidr"
68         echo "Will attempt to delete and recreate subnet $subnet_id"
69     fi
70 fi
71
72 if [ "$net_create" -eq "1" ]; then
73     # Delete the subnet and network to make sure it doesn't already exist
74     if openstack subnet list | grep start; then
75         openstack subnet delete $(openstack subnet list | grep start | awk '{print $4}')
76     fi
77     if openstack network show ctlplane; then
78         openstack network delete ctlplane
79     fi
80
81
82     NETWORK_ID=$(openstack network create --provider-network-type=flat --provider-physical-network=ctlplane ctlplane | grep " id " | awk '{print $4}')
83
84     NAMESERVER_ARG=""
85     if [ -n "${undercloud_nameserver:-}" ]; then
86         NAMESERVER_ARG="--dns-nameserver $undercloud_nameserver"
87     fi
88
89     openstack subnet create --network=$NETWORK_ID \
90         --gateway=$undercloud_network_gateway \
91         --subnet-range=$undercloud_network_cidr \
92         --allocation-pool start=$undercloud_dhcp_start,end=$undercloud_dhcp_end \
93         --host-route destination=169.254.169.254/32,gateway=$local_ip \
94         $NAMESERVER_ARG ctlplane
95 fi
96
97 # Disable nova quotas
98 openstack quota set --cores -1 --instances -1 --ram -1 $(openstack project show admin | awk '$2=="id" {print $4}')
99
100 # MISTRAL WORKFLOW CONFIGURATION
101 if [ "$(hiera mistral_api_enabled)" = "true" ]; then
102     # load workflows
103     for workbook in $(openstack workbook list | grep tripleo | cut -f 2 -d ' '); do
104         openstack workbook delete $workbook
105     done
106     for workflow in $(openstack workflow list | grep tripleo | cut -f 2 -d ' '); do
107         openstack workflow delete $workflow
108     done
109     for workbook in $(ls /usr/share/openstack-tripleo-common/workbooks/*); do
110         openstack workbook create $workbook
111     done
112
113   # Store the SNMP password in a mistral environment
114   if ! openstack workflow env show tripleo.undercloud-config &>/dev/null; then
115       TMP_MISTRAL_ENV=$(mktemp)
116       echo "{\"name\": \"tripleo.undercloud-config\", \"variables\": {\"undercloud_ceilometer_snmpd_password\": \"$snmp_readonly_user_password\"}}" > $TMP_MISTRAL_ENV
117       openstack workflow env create $TMP_MISTRAL_ENV
118    fi
119
120 fi
121
122 # IP forwarding is needed to allow the overcloud nodes access to the outside
123 # internet in cases where they are on an isolated network.
124 sysctl -w net.ipv4.ip_forward=1
125 # Make it persistent
126 echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/ip-forward.conf