Merge "Fix Neutron region in nova.conf"
[apex-tripleo-heat-templates.git] / ci / scripts / freeipa_setup.sh
1 #!/bin/bash
2 #
3 # Used environment variables:
4 #
5 #   - Hostname
6 #   - FreeIPAIP
7 #   - DirectoryManagerPassword
8 #   - AdminPassword
9 #   - UndercloudFQDN
10 #   - HostsSecret
11 #   - ProvisioningCIDR: If set, it adds the given CIDR to the provisioning
12 #                       interface (which is hardcoded to eth1)
13 #   - UsingNovajoin: If unset, we pre-provision the service principals
14 #                    needed for the overcloud deploy. If set, we skip this,
15 #                    since novajoin will do it.
16 #
17 set -eux
18
19 if [ -f "~/freeipa-setup.env" ]; then
20     source ~/freeipa-setup.env
21 elif [ -f "/tmp/freeipa-setup.env" ]; then
22     source /tmp/freeipa-setup.env
23 fi
24
25 if [ -n "$ProvisioningCIDR" ]; then
26     # Add address to provisioning network interface
27     ip link set dev eth1 up
28     ip addr add $ProvisioningCIDR dev eth1
29 fi
30
31 # Set DNS servers
32 echo "nameserver 8.8.8.8" >> /etc/resolv.conf
33 echo "nameserver 8.8.4.4" >> /etc/resolv.conf
34
35 yum -q -y remove openstack-dashboard
36
37 # Install the needed packages
38 yum -q install -y ipa-server ipa-server-dns epel-release rng-tools mod_nss git
39 yum -q install -y haveged
40
41 # Prepare hostname
42 hostnamectl set-hostname --static $Hostname
43
44 echo $FreeIPAIP `hostname` | tee -a /etc/hosts
45
46 # Set iptables rules
47 cat << EOF > freeipa-iptables-rules.txt
48 # Firewall configuration written by system-config-firewall
49 # Manual customization of this file is not recommended.
50 *filter
51 :INPUT ACCEPT [0:0]
52 :FORWARD ACCEPT [0:0]
53 :OUTPUT ACCEPT [0:0]
54 -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
55 -A INPUT -p icmp -j ACCEPT
56 -A INPUT -i lo -j ACCEPT
57 -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
58 #TCP ports for FreeIPA
59 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
60 -A INPUT -m state --state NEW -m tcp -p tcp --dport 443  -j ACCEPT
61 -A INPUT -m state --state NEW -m tcp -p tcp --dport 389 -j ACCEPT
62 -A INPUT -m state --state NEW -m tcp -p tcp --dport 636 -j ACCEPT
63 -A INPUT -m state --state NEW -m tcp -p tcp --dport 88  -j ACCEPT
64 -A INPUT -m state --state NEW -m tcp -p tcp --dport 464  -j ACCEPT
65 -A INPUT -m state --state NEW -m tcp -p tcp --dport 53  -j ACCEPT
66 #UDP ports for FreeIPA
67 -A INPUT -m state --state NEW -m udp -p udp --dport 88 -j ACCEPT
68 -A INPUT -m state --state NEW -m udp -p udp --dport 464 -j ACCEPT
69 -A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
70 -A INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT
71 -A INPUT -j REJECT --reject-with icmp-host-prohibited
72 -A FORWARD -j REJECT --reject-with icmp-host-prohibited
73 COMMIT
74 EOF
75
76 iptables-restore < freeipa-iptables-rules.txt
77
78 # Entropy generation; otherwise, ipa-server-install will lag.
79 chkconfig haveged on
80 systemctl start haveged
81
82 # Remove conflicting httpd configuration
83 rm -f /etc/httpd/conf.d/ssl.conf
84
85 # Set up FreeIPA
86 ipa-server-install -U -r `hostname -d|tr "[a-z]" "[A-Z]"` \
87                    -p $DirectoryManagerPassword -a $AdminPassword \
88                    --hostname `hostname -f`
89
90 # Authenticate
91 echo $AdminPassword | kinit admin
92
93 # Verify we have TGT
94 klist
95
96 if [ "$?" = '1' ]; then
97     exit 1
98 fi
99
100 if [ -z "$UsingNovajoin" ]; then
101     # Create undercloud host
102     ipa host-add $UndercloudFQDN --password=$HostsSecret --force
103
104     # Create overcloud nodes and services
105     git clone https://github.com/JAORMX/freeipa-tripleo-incubator.git
106     cd freeipa-tripleo-incubator
107     python create_ipa_tripleo_host_setup.py -w $HostsSecret -d $(hostname -d) \
108         --controller-count 1 --compute-count 1
109 fi