forked from openstack/heat-templates
/
389_Server.yaml
203 lines (203 loc) · 7.2 KB
/
389_Server.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
HeatTemplateFormatVersion: '2012-12-12'
Description: 389 LDAP server replica
Outputs:
Name:
Description: public DNS name of the 389 Server
Instance
Value:
Fn::Select:
- ip_address
- Fn::Select:
- '0'
- Fn::GetAtt: [PrimaryInterface, fixed_ips]
Id:
Description: Instance Id
Value:
Ref: Instance
Parameters:
Name: {Description: ServerName, Type: String}
IpAddress: {Description: Floating Ip Address to assign, Type: String}
VolumeId: {Description: Volume where data lives, Type: String}
PrimarySecurityGroup: {Description: Primary Security Group Id, Type: String}
ExtraUserData: {Default: '', Description: Extra UserData script, Type: String}
InstanceType:
Default: m1.small
Description: EC2 instance type (e.g. m1.large, m1.xlarge, m2.xlarge)
Type: String
InstanceZone:
Default: nova
Description: AvailabilityZone for this instance
Type: String
KeyName: {Description: Name of an existing EC2 KeyPair to enable SSH access, Type: String}
Image: {Description: Image to use, Type: String}
PrimaryNetworkId: {Description: PrimaryNetworkId, Type: String}
StartupTimeout: {Default: '700', Description: How long to wait on node coming up, Type: Number}
ServerGroupId:
Description: Server Group ID for the Server
Type: String
EpelRepo:
Default: 'http://mirror.utexas.edu/epel/6/x86_64/'
Description: Yum repo for epel.
Type: String
Resources:
PrimaryInterface:
Properties:
name:
Fn::Join:
- ''
- - {Ref: Name}
- -PrimaryPort
network_id: {Ref: PrimaryNetworkId}
security_groups:
- {Ref: PrimarySecurityGroup}
Type: OS::Neutron::Port
Instance:
Metadata:
AWS::CloudFormation::Init:
config:
packages:
yum:
lvm2: []
ntp: []
ntpdate: []
'389-ds': []
'389-admin': []
xorg-x11-xauth: []
liberation-sans-fonts: []
Properties:
name:
Fn::Join:
- ''
- - {Ref: Name}
availability_zone: {Ref: InstanceZone}
image: {Ref: Image}
flavor: {Ref: InstanceType}
key_name: {Ref: KeyName}
networks:
- port: {Ref: PrimaryInterface}
scheduler_hints:
group: {Ref: ServerGroupId}
user_data:
Fn::Base64:
Fn::Join:
- ''
- - "#!/bin/bash\n"
- "yum update -y aws-cfn-bootstrap\n"
- "## Error reporting helper function\n"
- "function error_exit\n"
- "{\n"
- " /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '"
- {Ref: WaitHandleServer}
- "'\n"
- " exit 1\n"
- "}\n"
- "function trap_error\n"
- "{\n"
- " error_exit \"Line: ${BASH_LINENO[0]}, ExitCode: $1\"\n"
- "}\n"
- "set -eu\n"
- "trap 'trap_error \"$?\"' ERR\n"
- "EPELREPO="
- {Ref: EpelRepo}
- "\n"
- "if [ \"x$EPELREPO\" != \"x\" ]; then\n"
- " cat > /etc/yum.repos.d/epel.repo << EOF\n"
- "[epel]\n"
- "name=epel repo\n"
- "baseurl="
- {Ref: EpelRepo}
- "\n"
- "failovermethod=priority\n"
- "enabled=1\n"
- "gpgcheck=0\n"
- "EOF\n"
- "fi\n"
- "## Initialize CloudFormation bits\n"
- "/opt/aws/bin/cfn-init -s "
- {Ref: "AWS::StackName"}
- " -r Instance --region "
- {Ref: "AWS::Region"}
- " > /tmp/cfn-init.log 2>&1 || error_exit $(</tmp/cfn-init.log)\n"
- "while [ ! -e /dev/vdb ]; do echo waiting for /dev/vdb to attach; sleep 10; done\n"
- "/etc/init.d/sshd stop || true \n"
- "NAME=\""
- {Ref: Name}
- "\"\n"
- "service ntpd start\n"
- "chkconfig ntpd on\n"
- "lvchange /dev/$NAME-vg0/$NAME-data -a y || true\n"
- "service iptables stop || true\n"
- "chkconfig iptables off || true\n"
- "mkdir -p /usr/lib64/dirsrv/slapd-$NAME\n"
- "chown nobody.nobody /var/run/dirsrv/\n"
- "mkdir -p /var/log/dirsrv/admin-serv\n"
- "mkdir -p /var/log/dirsrv/slapd-$NAME\n"
- "chown -R nobody.nobody /var/log/dirsrv/\n"
- "mkdir /var/lock/dirsrv/slapd-$NAME\n"
- "chown nobody.nobody /var/lock/dirsrv/slapd-$NAME\n"
- "echo \"/dev/$NAME-vg0/$NAME-data\"' /srv ext4 defaults,auto,noatime 0 0'"
- " | tee -a /etc/fstab\n"
- "echo \"/srv/389/usr-lib/slapd-$NAME /usr/lib64/dirsrv/slapd-$NAME \"' none defaults,bind 0 0'"
- " | tee -a /etc/fstab\n"
- "echo \"/srv/389/lib /var/lib/dirsrv \"' none defaults,bind 0 0'"
- " | tee -a /etc/fstab\n"
- "echo \"/srv/389/etc /etc/dirsrv \"' none defaults,bind 0 0'"
- " | tee -a /etc/fstab\n"
- "mount /srv\n"
- "echo "
- {Ref: IpAddress}
- " $NAME >> /etc/hosts\n"
- "hostname $NAME\n"
- "sed -i 's/HOSTNAME=.*/HOSTNAME='$NAME'/' /etc/sysconfig/network\n"
- "mv /etc/ssh /etc/ssh.orig\n"
- "ln -s /srv/etc/ssh /etc/ssh\n"
- "/etc/init.d/sshd restart || true \n"
- "mount /etc/dirsrv\n"
- "mount /var/lib/dirsrv\n"
- "mount /usr/lib64/dirsrv/slapd-$NAME\n"
- "selinuxenabled\n"
- "if [ $? -eq 0 ]; then\n"
- " fixfiles restore /srv/\n"
- " for x in /etc/dirsrv /usr/lib64/dirsrv /var/lib/dirsrv /var/log/dirsrv /var/run/dirsrv; do\n"
- " restorecon -r $x\n"
- " done\n"
- "#FIXME Even after the above, the admin server is still grumpy due to selinux brokenness. Just going to disable it for now.\n"
- " setenforce 0\n"
- " sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/sysconfig/selinux /etc/selinux/config\n"
- "fi\n"
- "chkconfig dirsrv on\n"
- "chkconfig dirsrv-admin on\n"
- "service dirsrv-admin start\n"
- "service dirsrv start\n"
- "## Extra userdata\n"
- {Ref: ExtraUserData}
- "\n"
- "## CloudFormation signal that setup is complete\n"
- "/opt/aws/bin/cfn-signal -e 0 -r \"Server setup complete\" '"
- {Ref: WaitHandleServer}
- "'\n"
Type: OS::Nova::Server
VolumeMount:
Properties:
Device: /dev/vdb
InstanceId: {Ref: Instance}
VolumeId: {Ref: VolumeId}
Type: AWS::EC2::VolumeAttachment
Floating-IP:
Properties:
NetworkInterfaceId:
Ref: PrimaryNetworkId
InstanceId:
Ref: Instance
EIP:
Ref: IpAddress
Type: AWS::EC2::EIPAssociation
WaitConditionServer:
DependsOn: Instance
Properties:
Handle: {Ref: WaitHandleServer}
Timeout: {Ref: StartupTimeout}
Type: AWS::CloudFormation::WaitCondition
WaitHandleServer:
Properties: {}
Type: AWS::CloudFormation::WaitConditionHandle