CloudInit Introduction

5,183 views

Published on

CloudInit introduction,
Use case on Amazon AWS EC2

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,183
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
26
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

CloudInit Introduction

  1. 1. Xebia Workshop CloudInit Xebia: OpenCSI: Bertrand Dechoux Bruno Bonfils Charles Blonde Cyrille Le Clerc Emmanuel Servent Eric BriandSaturday, August 13, 11
  2. 2. Introduction  Goal: bootstrap a cloud instance  How: give a file as parameter for the first instance start ▶ Retrievedfrom http://169.254.169.254/latest/user-data ▶ May be a multipart file  Ubuntu project, exist for RPM based systems 2Saturday, August 13, 11
  3. 3. Some recipes examples Set the hostname Import SSH keys Declare apt mirror Install packages Execute commands Execute scripts Bootstrap Puppet / Chef Detailed sample : http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/view/head:/doc/examples/cloud-config.txt 3Saturday, August 13, 11
  4. 4. Advices CloudInit is not very well documented, use the source, good luck! Choose to use existing recipes or write your own 4Saturday, August 13, 11
  5. 5. cloud-config: the key CloudInit script #cloud-config timezone: Europe/Paris packages: - puppet - java-1.6.0-openjdk - tomcat6 - tomcat6-webapps runcmd: - [service, tomcat6, start] - [chkconfig, tomcat6, on] Declarative YAML based configuration 5Saturday, August 13, 11
  6. 6. My own shell script #!/usr/bin/env bash instanceId=$(curl http://169.254.169.254/latest/meta-data/instance-id) fqdn="$instanceId.aws.labs.opencsi.com" sed -i.bak "s/HOSTNAME=.*/HOSTNAME=${fqdn}/" /etc/sysconfig/network hostname ${fqdn} echo "127.0.0.1 $id $fqdn" >> /etc/hosts # Now bootstrap puppet puppetd --no-daemonize --onetime -v --server=puppetmaster.aws.labs.opencsi.com 6Saturday, August 13, 11
  7. 7. My own shell script #!/usr/bin/env python ... # INJECT DATABASE URL IN CATALINA.PROPERTIES f = open(catalinaBase + /conf/catalina.properties, ab) f.write(nn# BEGIN OF ADDED BY CLOUD-INIT #n) f.write(jdbc.url=jdbc:mysql://my-db-host:3306/petclinicn) f.write(jdbc.username=petclinicn) f.write(jdbc.password=petclinicn) f.write(nn# END OF ADDED BY CLOUD-INIT #n) f.close() # DOWNLOAD AND DEPLOY WAR url = http://my-nexus/fr/xebia/.../1.0.2/petclinic-1.0.2.war URLopener().retrieve(url, catalinaBase + /webapps/petclinic.war) print(Downloaded + url + to + filename) Inject database config in Tomcat Deploy war 7Saturday, August 13, 11
  8. 8. CloudInit resources https://help.ubuntu.com/community/CloudInit https://code.launchpad.net/~cloud-init-dev/ cloud-init/trunk 8Saturday, August 13, 11
  9. 9. The Workshop“Discover Java Infra as Code with Amazon AWS” http://code.google.com/p/xebia-france/wiki/ JavaInfrastructureAsCodeWithAmazonAwsWorkshop 9Saturday, August 13, 11

×