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