Merge "Add host logging for redis service template"
[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 if [ "$(hiera neutron_api_enabled)" = "true" ]; then
49     PHYSICAL_NETWORK=ctlplane
50
51     ctlplane_id=$(openstack network list -f csv -c ID -c Name --quote none | tail -n +2 | grep ctlplane | cut -d, -f1)
52     subnet_ids=$(openstack subnet list -f csv -c ID --quote none | tail -n +2)
53     subnet_id=
54
55     for subnet_id in $subnet_ids; do
56         network_id=$(openstack subnet show -f value -c network_id $subnet_id)
57         if [ "$network_id" = "$ctlplane_id" ]; then
58             break
59         fi
60     done
61
62     net_create=1
63     if [ -n "$subnet_id" ]; then
64         cidr=$(openstack subnet show $subnet_id -f value -c cidr)
65         if [ "$cidr" = "$undercloud_network_cidr" ]; then
66             net_create=0
67         else
68             echo "New cidr $undercloud_network_cidr does not equal old cidr $cidr"
69             echo "Will attempt to delete and recreate subnet $subnet_id"
70         fi
71     fi
72
73     if [ "$net_create" -eq "1" ]; then
74         # Delete the subnet and network to make sure it doesn't already exist
75         if openstack subnet list | grep start; then
76             openstack subnet delete $(openstack subnet list | grep start | awk '{print $4}')
77         fi
78         if openstack network show ctlplane; then
79             openstack network delete ctlplane
80         fi
81
82
83         NETWORK_ID=$(openstack network create --provider-network-type=flat --provider-physical-network=ctlplane ctlplane | grep " id " | awk '{print $4}')
84
85         NAMESERVER_ARG=""
86         if [ -n "${undercloud_nameserver:-}" ]; then
87             NAMESERVER_ARG="--dns-nameserver $undercloud_nameserver"
88         fi
89
90         openstack subnet create --network=$NETWORK_ID \
91             --gateway=$undercloud_network_gateway \
92             --subnet-range=$undercloud_network_cidr \
93             --allocation-pool start=$undercloud_dhcp_start,end=$undercloud_dhcp_end \
94             --host-route destination=169.254.169.254/32,gateway=$local_ip \
95             $NAMESERVER_ARG ctlplane
96     fi
97 fi
98
99 if [ "$(hiera nova_api_enabled)" = "true" ]; then
100     # Disable nova quotas
101     openstack quota set --cores -1 --instances -1 --ram -1 $(openstack project show admin | awk '$2=="id" {print $4}')
102 fi
103
104 # MISTRAL WORKFLOW CONFIGURATION
105 if [ "$(hiera mistral_api_enabled)" = "true" ]; then
106     # load workflows
107     for workbook in $(openstack workbook list | grep tripleo | cut -f 2 -d ' '); do
108         openstack workbook delete $workbook
109     done
110     for workflow in $(openstack workflow list | grep tripleo | cut -f 2 -d ' '); do
111         openstack workflow delete $workflow
112     done
113     for workbook in $(ls /usr/share/openstack-tripleo-common/workbooks/*); do
114         openstack workbook create $workbook
115     done
116
117   # Store the SNMP password in a mistral environment
118   if ! openstack workflow env show tripleo.undercloud-config &>/dev/null; then
119       TMP_MISTRAL_ENV=$(mktemp)
120       echo "{\"name\": \"tripleo.undercloud-config\", \"variables\": {\"undercloud_ceilometer_snmpd_password\": \"$snmp_readonly_user_password\"}}" > $TMP_MISTRAL_ENV
121       openstack workflow env create $TMP_MISTRAL_ENV
122    fi
123
124 fi
125
126 # IP forwarding is needed to allow the overcloud nodes access to the outside
127 # internet in cases where they are on an isolated network.
128 sysctl -w net.ipv4.ip_forward=1
129 # Make it persistent
130 echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/ip-forward.conf