Created
December 8, 2013 21:34
-
-
Save larsks/7864119 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Content-Type: multipart/mixed; boundary="===============6288321547629642809==" | |
MIME-Version: 1.0 | |
--===============6288321547629642809== | |
Content-Type: text/cloud-config; charset="us-ascii" | |
MIME-Version: 1.0 | |
Content-Transfer-Encoding: 7bit | |
Content-Disposition: attachment; filename="cloud-config" | |
user: ec2-user | |
cloud_config_modules: | |
- locale | |
- set_hostname | |
- timezone | |
- update_etc_hosts | |
- update_hostname | |
# Capture all subprocess output into a logfile | |
# Useful for troubleshooting cloud-init issues | |
output: {all: '| tee -a /var/log/cloud-init-output.log'} | |
--===============6288321547629642809== | |
Content-Type: text/cloud-boothook; charset="us-ascii" | |
MIME-Version: 1.0 | |
Content-Transfer-Encoding: 7bit | |
Content-Disposition: attachment; filename="boothook.sh" | |
#!/bin/bash | |
setenforce 0 | |
useradd -m ec2-user | |
echo -e 'ec2-user\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers | |
# in case heat-cfntools has been installed from package but no symlinks | |
# are yet in /opt/aws/bin/ | |
cfn-create-aws-symlinks | |
# Do not remove - the cloud boothook should always return success | |
exit 0 | |
--===============6288321547629642809== | |
Content-Type: text/part-handler; charset="us-ascii" | |
MIME-Version: 1.0 | |
Content-Transfer-Encoding: 7bit | |
Content-Disposition: attachment; filename="part-handler.py" | |
#part-handler | |
# Licensed under the Apache License, Version 2.0 (the "License"); you may | |
# not use this file except in compliance with the License. You may obtain | |
# a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
# License for the specific language governing permissions and limitations | |
# under the License. | |
import datetime | |
import errno | |
import os | |
def list_types(): | |
return(["text/x-cfninitdata"]) | |
def handle_part(data, ctype, filename, payload): | |
if ctype == "__begin__": | |
try: | |
os.makedirs('/var/lib/heat-cfntools', 0o700) | |
except OSError as e: | |
if e.errno != errno.EEXIST: | |
raise | |
return | |
if ctype == "__end__": | |
return | |
with open('/var/log/part-handler.log', 'a') as log: | |
timestamp = datetime.datetime.now() | |
log.write('%s filename:%s, ctype:%s\n' % (timestamp, filename, ctype)) | |
if ctype == 'text/x-cfninitdata': | |
with open('/var/lib/heat-cfntools/%s' % filename, 'w') as f: | |
f.write(payload) | |
# TODO(sdake) hopefully temporary until users move to heat-cfntools-1.3 | |
with open('/var/lib/cloud/data/%s' % filename, 'w') as f: | |
f.write(payload) | |
--===============6288321547629642809== | |
Content-Type: text/x-cfninitdata; charset="us-ascii" | |
MIME-Version: 1.0 | |
Content-Transfer-Encoding: 7bit | |
Content-Disposition: attachment; filename="cfn-userdata" | |
--===============6288321547629642809== | |
Content-Type: text/x-shellscript; charset="us-ascii" | |
MIME-Version: 1.0 | |
Content-Transfer-Encoding: 7bit | |
Content-Disposition: attachment; filename="loguserdata.py" | |
#!/usr/bin/env python | |
# Licensed under the Apache License, Version 2.0 (the "License"); you may | |
# not use this file except in compliance with the License. You may obtain | |
# a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
# License for the specific language governing permissions and limitations | |
# under the License. | |
import errno | |
import datetime | |
import logging | |
import pkg_resources | |
import os | |
import subprocess | |
import sys | |
from distutils.version import LooseVersion | |
VAR_PATH = '/var/lib/heat-cfntools' | |
LOG = logging.getLogger('heat-provision') | |
def chk_ci_version(): | |
v = LooseVersion(pkg_resources.get_distribution('cloud-init').version) | |
return v >= LooseVersion('0.6.0') | |
def init_logging(): | |
LOG.setLevel(logging.INFO) | |
LOG.addHandler(logging.StreamHandler()) | |
fh = logging.FileHandler("/var/log/heat-provision.log") | |
os.chmod(fh.baseFilename, 0o600) | |
LOG.addHandler(fh) | |
def call(args): | |
class LogStream(object): | |
def write(self, data): | |
LOG.info(data) | |
LOG.info('%s\n' % ' '.join(args)) | |
try: | |
ls = LogStream() | |
p = subprocess.Popen(args, stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE) | |
data = p.communicate() | |
if data: | |
for x in data: | |
ls.write(x) | |
except OSError as ex: | |
if ex.errno == errno.ENOEXEC: | |
LOG.error('Userdata empty or not executable: %s\n' % str(ex)) | |
return os.EX_OK | |
else: | |
LOG.error('OS error running userdata: %s\n' % str(ex)) | |
return os.EX_OSERR | |
except Exception as ex: | |
LOG.error('Unknown error running userdata: %s\n' % str(ex)) | |
return os.EX_SOFTWARE | |
return p.returncode | |
def main(): | |
if not chk_ci_version(): | |
# pre 0.6.0 - user data executed via cloudinit, not this helper | |
LOG.info('Unable to log provisioning, need a newer version of' | |
' cloud-init\n') | |
return -1 | |
userdata_path = os.path.join(VAR_PATH, 'cfn-userdata') | |
os.chmod(userdata_path, 0o700) | |
LOG.info('Provision began: %s\n' % datetime.datetime.now()) | |
returncode = call([userdata_path]) | |
LOG.info('Provision done: %s\n' % datetime.datetime.now()) | |
if returncode: | |
return returncode | |
if __name__ == '__main__': | |
init_logging() | |
code = main() | |
if code: | |
LOG.error('Provision failed with exit code %s' % code) | |
sys.exit(code) | |
provision_log = os.path.join(VAR_PATH, 'provision-finished') | |
# touch the file so it is timestamped with when finished | |
with file(provision_log, 'a'): | |
os.utime(provision_log, None) | |
--===============6288321547629642809== | |
Content-Type: text/x-cfninitdata; charset="us-ascii" | |
MIME-Version: 1.0 | |
Content-Transfer-Encoding: 7bit | |
Content-Disposition: attachment; filename="cfn-watch-server" | |
http://192.168.122.136:8003 | |
--===============6288321547629642809== | |
Content-Type: text/x-cfninitdata; charset="us-ascii" | |
MIME-Version: 1.0 | |
Content-Transfer-Encoding: 7bit | |
Content-Disposition: attachment; filename="cfn-metadata-server" | |
http://192.168.122.136:8000 | |
--===============6288321547629642809== | |
Content-Type: text/x-cfninitdata; charset="us-ascii" | |
MIME-Version: 1.0 | |
Content-Transfer-Encoding: 7bit | |
Content-Disposition: attachment; filename="cfn-boto-cfg" | |
[Boto] | |
debug = 0 | |
is_secure = 0 | |
https_validate_certificates = 1 | |
cfn_region_name = heat | |
cfn_region_endpoint = 192.168.122.136 | |
cloudwatch_region_name = heat | |
cloudwatch_region_endpoint = 192.168.122.136 | |
--===============6288321547629642809==-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment