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