Auto-deploy an OpenStack-Ansible using "nova boot" with user-data

Building an OpenStack-Ansible test deployment within an OpenStack cloud has never been simpler; just boot the node, pass some user-data, profit! Before building instances, check the system requirements to ensure you're building VMs of an adequate size.


If you're access to the OpenStack environment is through horizon simply go to the instances panel and click "Lanuch Instance". Once loaded click through the various panels adding keys, security groups, and networking.

Before you Launch the node, click the "Post-Creation" tab and add in a user-data script by selecting the "Direct Input" option.

Now boot the instance and check back in on it after a little while.


This same thing can be accomplished by using the nova CLI tools. Run the nova boot command passing in the user-data script as an argument.

User-data script
#!/bin/bash
apt-get update
apt-get install -y tmux git vim python
# TMUX is used here to open a terminal that you can connect to
#  post build and troubleshoot things should issues arise.
tmux new-session -d -s build-osa
tmux select-pane -t 0
tmux send-keys "cd /opt" C-m
tmux send-keys "git clone https://github.com/openstack/openstack-ansible" C-m
tmux send-keys "cd openstack-ansible" C-m
tmux send-keys "./scripts/gate-check-commit.sh" C-m
# Wait for the ansible file to appear and then start streaming it
while ! [[ -f /openstack/log/ansible-logging/ansible.log ]]; do
   echo "waiting for ansible log file: /openstack/log/ansible-logging/ansible.log"
   sleep 5
done
tail -f /openstack/log/ansible-logging/ansible.log
Boot the node
nova boot --image ubuntu-server-14.04 --flavor m2.medium --nic net-id="${NEUTRON_NETWORK_ID}" --key-name "${SPECIALKEYNAME}" --user-data ~/projects/auto-build-osa.sh "${NODE_NAME}"

In this example I'm setting an SSH key name of ${SPECIALKEYNAME} and passing in the user-data script which I've saved at ~/projects/auto-build-osa.sh. As you construct you command make sure you set the image, flavor, and nic to values that match your cloud.

Once nova boots the instance the user-data script will be used to bootstrap the node and if all goes well you'll have a functional OpenStack-Ansible all in one deployment.


To check on the status of your build you have several options. You could log-in to the node and tail the ansible logs, connect to the running tmux session with however I find it a lot easier to simply query the console log periodically to see when things are done. This can be done in Horizon or by using the nova CLI tools.

Query logs from Horizon

Click on your instance and the the "Log" tab.

Query logs from the CLI
nova console-log "${NODE_NAME}"
Connect to tmux from within the instance
tmux attach -t build-osa