For those of you who have not heard or used ensemble before, Ensemble is a quick way to allow administrator to deploy services to the Amazon EC2 cloud. Thanks to the pre-build formulas, you can easily deploy a wordpress blog in less than 5 minutes!!

To start, you will first need to have an Amazon EC2 account. Once the registration is completed, from the Amazon Account Portal, you can find your access key and secret key there. These information will be used later on to start/stop your EC2 instances. With all the said and done, let’s start the fun stuff!

First, add the ensemble ppa to your system:

sudo add-apt-repository ppa:ensemble/ppa
sudo apt-get update && sudo apt-get install ensemble

Then, run the command to setup the environment:

ensemble

Now, you need to edit the config file put in your EC2 access key and secret key:

sudo nano ~/.ensemble/environments.yaml

After that the file (environments.yaml) should look like:

ensemble: environments

environments:
sample:
type: ec2
control-bucket: ensemble-e1446ba830f0458fb04a9a86588749bb
admin-secret: 6c14633ea540477691f860e151cde0f7
access-key: _Your_Access_Key_Here_
secret-key: _Your_Secret_Key_Here_

Now, you will be able to use the ensemble command to control/deploy your EC2 cloud~

Let’s take a look at an example:

A. Before you begin, you will need to launch the first instance to manage the rest of the deployment. To do that, you run:

ensemble bootstrap

If the command is working successfully, it should return:

2011-07-19 17:39:18,622 INFO Bootstrapping environment ‘sample’ (type: ec2)…
2011-07-19 17:39:25,079 INFO ‘bootstrap’ command finished successfully

B. You can go check on the Amazon portal to ensure the node is running OR you can run the status command to see if the instance is up and running now:

ensemble status

If the instance is not ready, you will see:

2011-07-19 17:40:55,829 INFO Connecting to environment.
2011-07-19 17:40:59,217 ERROR Connection refused
Unhandled error in Deferred:
Traceback (most recent call last):
Failure: txzookeeper.client.ConnectionTimeoutException: could not connect before timeout
ProviderError: Interaction with machine provider failed: ConnectionTimeoutException(‘could not connect before timeout after 2 retries’,)
2011-07-19 17:41:26,277 ERROR ProviderError: Interaction with machine provider failed: ConnectionTimeoutException(‘could not connect before timeout after 2 retries’,)

Just wait a few minutes and run it again. If everything is working now, you should see:

2011-07-19 17:41:52,668 INFO Connecting to environment.
machines:
0: {dns-name: ec2-50-16-161-148.compute-1.amazonaws.com, instance-id: i-37569856}
services: {}
2011-07-19 17:41:58,186 INFO ‘status’ command finished successfully

C. Now you will need to change directory where the ensemble secret formulas are before you deploy the services:

cd /usr/share/doc/ensemble

D. Now, you can start deploying the word press and mysql services on your EC2 cloud by running:

ensemble deploy –repository=examples wordpress
ensemble deploy –repository=examples mysql

When this is done, you should have three instances running on your EC2 cloud.

E. Finally, to let them know the other services exists and to use each other, you run the command:

ensemble add-relation mysql wordpress

If this return:

2011-07-19 17:50:01,038 INFO Connecting to environment.
2011-07-19 17:50:07,706 INFO Added mysql relation to all service units.
2011-07-19 17:50:07,706 INFO ‘add_relation’ command finished successfully

Then, it means you have successfully deploy your own wordpress service to the world!

F. To check the status and the related information, you can use the status command again. It will tell you what/where the systems/services are running right now:

machines:
0: {dns-name: ec2-50-16-161-148.compute-1.amazonaws.com, instance-id: i-37569856}
1: {dns-name: ec2-50-19-25-157.compute-1.amazonaws.com, instance-id: i-8d539dec}
2: {dns-name: ec2-184-72-167-215.compute-1.amazonaws.com, instance-id: i-41509e20}
services:
mysql:
formula: local:mysql-11
relations: {db: wordpress}
units:
mysql/0:
machine: 1
relations: {}
state: null
wordpress:
formula: local:wordpress-29
relations: {db: mysql}
units:
wordpress/0:
machine: 2
relations: {}
state: null
2011-07-19 17:52:49,060 INFO ‘status’ command finished successfully

In my output, the mysql services is running on machine 1, and wordpress is running on machine 2. However, the service is not ready yet, if you notice the line state: null.

Wait a few minutes and try again until you see the output like:

2011-07-19 17:54:53,987 INFO Connecting to environment.
machines:
0: {dns-name: ec2-50-16-161-148.compute-1.amazonaws.com, instance-id: i-37569856}
1: {dns-name: ec2-50-19-25-157.compute-1.amazonaws.com, instance-id: i-8d539dec}
2: {dns-name: ec2-184-72-167-215.compute-1.amazonaws.com, instance-id: i-41509e20}
services:
mysql:
formula: local:mysql-11
relations: {db: wordpress}
units:
mysql/0:
machine: 1
relations:
db: {state: up}
state: started
wordpress:
formula: local:wordpress-29
relations: {db: mysql}
units:
wordpress/0:
machine: 2
relations:
db: {state: up}
state: started
2011-07-19 17:55:06,462 INFO ‘status’ command finished successfully

Then the system has finish its setup.

G. To really look under the hood and see what is going on, you can use the debug-log command:

ensemble debug-log

Until you see the message:

2011-07-19 17:55:22,591 unit:wordpress/0: hook.executor DEBUG: Hook complete: /var/lib/ensemble/units/wordpress-0/formula/hooks/db-relation-changed

Your wordpress is ready!

H. Now, go to the wordpress machine address from the status ouput, in my case it is machine 1. The address for machine one is “ec2-50-19-25-157.compute-1.amazonaws.com”. Copy and paste that to your browser, you will be asked to configure username and password to complete the setup!

I. When you are done, just use the shutdown command to stop all the services and instances:

ensemble shutdown

Hello WordPress! Hello Ensemble!!

References:
[1] Ensemble Tutorial:

https://ensemble.ubuntu.com/docs/user-tutorial.html

[2] Zero to Ensemble in 5 mins:

http://www.youtube.com/user/ubuntucloud#p/a/u/1/qxMhKbDSbOw