-
Notifications
You must be signed in to change notification settings - Fork 1
/
userdata-cloud-init-multimime.txt.template
208 lines (171 loc) · 7.08 KB
/
userdata-cloud-init-multimime.txt.template
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
204
205
206
207
208
Content-Type: multipart/mixed; boundary="===============2205584129673038508=="
MIME-Version: 1.0
--===============2205584129673038508==
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config"
#cloud-config
# Cloud-Init Hints:
# * Some default settings are in /etc/cloud/cloud.cfg
# * Some examples at: http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/files/head:/doc/examples/
# * CloudInit Module sourcecode at: http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/files/head:/cloudinit/config/
preserve_hostname: true
manage_etc_hosts: false
# dynamically set hostname using the instance's instanceid
bootcmd:
- cloud-init-per instance my_set_hostname sh -xc "echo ${instancePrefix}-${nodeType}-$INSTANCE_ID > /etc/hostname; hostname -F /etc/hostname"
- cloud-init-per instance my_etc_hosts sh -xc "sed -i -e '/^127.0.1.1/d' /etc/hosts; echo 127.0.1.1 ${instancePrefix}-${nodeType}-$INSTANCE_ID.${instanceDomain} ${instancePrefix}-${nodeType}-$INSTANCE_ID >> /etc/hosts"
- cloud-init-per instance my_get_missing_key sh -xc "sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4528B6CD9E61EF26"
# make user-data scripts always run on boot
cloud_final_modules:
- rightscale_userdata
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- [scripts-user, always]
- keys-to-console
- phone-home
- final-message
# Add apt repositories
apt_sources:
# Enable "multiverse" repos
- source: deb $MIRROR $RELEASE multiverse
- source: deb-src $MIRROR $RELEASE multiverse
- source: deb $MIRROR $RELEASE-updates multiverse
- source: deb-src $MIRROR $RELEASE-updates multiverse
- source: deb http://security.ubuntu.com/ubuntu $RELEASE-security multiverse
- source: deb-src http://security.ubuntu.com/ubuntu $RELEASE-security multiverse
# Enable "partner" repos
- source: deb http://archive.canonical.com/ubuntu $RELEASE partner
- source: deb-src http://archive.canonical.com/ubuntu $RELEASE partner
# Enable PuppetLabs repos (for latest version of puppet)
- source: deb http://apt.puppetlabs.com $RELEASE main dependencies
keyid: 7F438280EF8D349F # GPG key ID published on a key server
filename: puppetlabs.list
# Run 'apt-get update' on first boot
apt_update: true
# Run 'apt-get upgrade' on first boot
apt_upgrade: true
# Reboot after package install/upgrade if needed (e.g. if kernel update)
apt_reboot_if_required: True
# Install additional packages on first boot
packages:
- nfs-common # for using AWS EFS
- wget
- htop
- git
- curl
- puppet
- ruby # Used to install librarian-puppet
- ruby-dev
- unzip
- make
# run commands
# runcmd contains a list of either lists or a string
# each item will be executed in order
runcmd:
- mkdir -p /efs
- echo "${efsDnsName}:/ /efs nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 0 0" >> /etc/fstab
- mount -a -t nfs4
- mkdir -p ${workdir}
# Tell sudo to respect SSH Agent forwarding
- [sh, -c, "umask 0226; echo 'Defaults env_keep += \"SSH_AUTH_SOCK\"' > /etc/sudoers.d/ssh-auth-sock"]
# Install AWS CLI
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- unzip awscliv2.zip
- ./aws/install
# Install librarian-puppet for retrieving dependent puppet modules from github (>1.0.3 requires >=Ruby 1.9)
- gem install highline --version 1.6.1
- gem install json --version 1.8.3
- gem install librarian-puppet --version 1.0.3
# Get the github ssh key out of s3 so we can clone from our private github projects
- aws --region ${awsRegion} s3 cp s3://${bootstrapBucket}/${githubKeyName} /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa
# Add github.com to known_hosts
- ssh -T -oStrictHostKeyChecking=no [email protected]
# set the locale
locale: en_US.UTF-8
# timezone: set the timezone for this instance
timezone: UTC
# Log all cloud-init process output (info & errors) to a logfile
output: {all: ">> /var/log/cloud-init-output.log"}
# final_message written to log when cloud-init processes are finished
final_message: "System boot (via cloud-init) is COMPLETE, after $UPTIME seconds. Finished at $TIMESTAMP"
--===============2205584129673038508==
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="user-script"
#!/bin/bash
rm -rf /etc/puppet
git clone -b ${puppetDuracloudMillBranch} [email protected]:${puppetDuracloudMillRepoOwner}/puppet-duracloud-mill.git /etc/puppet/
# Run librarian-puppet
cd /etc/puppet && HOME=/root librarian-puppet install
# set up custom Puppet Facter facts
mkdir -p /etc/facter/facts.d
cat << 'EOF' > /etc/facter/facts.d/duracloud-mill
#!/usr/bin/env python
import subprocess
data = {
"dc_mill_node_type":"${nodeType}", # 'dup-producer', 'bit-producer' ,'worker', 'storage-stats', or 'sentinel'
"dc_mill_log_level":"INFO",
"dc_mill_config_file":"/home/duracloud/mill-config.properties",
"dc_mill_version":"${jarVersion}",
"dc_workman_tmpdir":"${workdir}",
"release_mode":"${release_mode}",
"sumo_access_id":"${sumo_access_id}",
"sumo_access_key":"${sumo_access_key}",
"sumo_collector_name":"${sumo_collector_name}"
}
for k in data:
print "%s=%s" % (k,data[k])
EOF
chmod +x /etc/facter/facts.d/duracloud-mill
# create mill config file
millConfigFile=/home/duracloud//mill-config.properties
millConfigDir="$(dirname $millConfigFile)"
mkdir -p $millConfigDir
cat << 'EOF' > $millConfigFile
#MILL_CONFIG
EOF
# create bit inclusion list
bitInclusionDir="$(dirname ${looping.bit.inclusion-list-file})"
mkdir -p $bitInclusionDir
cat << 'EOF' > ${looping.bit.inclusion-list-file}
#BIT_INCLUSIONS
EOF
#create bit exclusion list
bitExclusionDir="$(dirname ${looping.bit.exclusion-list-file})"
mkdir -p $bitExclusionDir
cat << 'EOF' > ${looping.bit.exclusion-list-file}
#BIT_EXCLUSIONS
EOF
# create storagestats inclusion list
storageStatsInclusionDir="$(dirname ${looping.storagestats.inclusion-list-file})"
mkdir -p $storageStatsInclusionDir
cat << 'EOF' > ${looping.storagestats.inclusion-list-file}
#STORAGE_STATS_INCLUSIONS
EOF
#create storagestats exclusion list
storageStatsExclusionDir="$(dirname ${looping.storagestats.exclusion-list-file})"
mkdir -p $storageStatsExclusionDir
cat << 'EOF' > ${looping.storagestats.exclusion-list-file}
#STORAGE_STATS_EXCLUSIONS
EOF
#copy sumo.json file into place
# I'm unable to get SumoLogic/sumologic-collector-puppet-module to respect the
# path to the sources json file in puppet-duracloud-mill. So the following
# file copy put the file where sumo expects it.
mkdir -p /usr/local/sumo
cp /etc/puppet/sumo/duracloud_sources.json /usr/local/sumo/sources.json
# Run puppet
puppet apply /etc/puppet/manifests/site.pp
#apply permissions after puppet to ensure no conflict
chown -R duracloud:duracloud $millConfigDir
chown -R duracloud:duracloud $bitInclusionDir
chown -R duracloud:duracloud $bitExclusionDir
chown -R duracloud:duracloud $storageStatsInclusionDir
chown -R duracloud:duracloud $storageStatsExclusionDir
chown -R duracloud:duracloud /efs/
chown -R duracloud:duracloud ${workdir}
--===============2205584129673038508==--