How To Create A DreamHost Cloud Server From An Ansible Playbook
Install Shade library
Shade is a library developed by OpenStack to simplify interactions with OpenStack clouds, like DreamHost.
$ pip install shade
Write a Playbook to Launch a Server
Create a file named launch-server.yaml, that will be our playbook.
The first part of the playbook is a list of hosts that your playbook will run on, we only have one, localhost.
- hosts: localhostThen we need to define a list of tasks to perform in this playbook. We will only have one that launches an Ubuntu Xenial server on DreamCompute.
tasks:
- name: launch an Ubuntu serverNext part of the playbook uses the os_server (OpenStack Server) module. This defines what the server has to look like in DreamCompute.
os_server:First step is to authenticate to DreamCompute; substitute {username} with your DreamCompute username, {password} with your DreamCompute password, and {project} with your DreamCompute project. You’ll find those in the OpenStack RC file.
auth:
auth_url: https://iad2.dream.io:5000
username: {username}
password: {password}
project_name: {project}Next lines define some elements of the new server.
state: present
name: ansible-vm1
image: Ubuntu-16.04
key_name: {keyname}
flavor: 50
network: public
wait: yesLets break down the previous few lines:
stateis the state of the server, possible values arepresentorabsentnameis the name of the server to create; can be any valueimageis the image to boot the server from; possible values are visible on DreamHost Cloud web panel; the variable accepts either image name or UUIDkey_nameis the name of the public key to add to the server once it is created; this can be any key has already been added to DreamCompute.flavoris the flavor of server to boot; this defines how much RAM and CPU your server will have; the variable accepts either the name of a flavor (gp1.semisonic) or the ID (50, 100, 200, etc)networkis the network to put your server on. In DreamHost Cloud case it is thepublicnetwork.waitset to yes forces the playbook to wait for the server to be created before continuing.
Running the Playbook
Run the Ansible playbook:
$ ansible-playbook launch-server.yamlYou should see output like
PLAY [localhost]
***************************************************************
TASK [setup]
*******************************************************************
ok: [localhost]
TASK [launch an Ubuntu server]
***********************************************
changed: [localhost]
PLAY RECAP
*********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0Now if you check the DreamHost Cloud dashboard you should see a new instance named “ansible-vm1”