add a simple playbook to launch an instance

Start a demo playbook to launch an instance for capture.

Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-02-07 22:48:09 +00:00
parent ee6c90bb52
commit f10650a24f
6 changed files with 160 additions and 0 deletions

3
.gitignore vendored
View File

@ -59,3 +59,6 @@ releasenotes/build
/clouds.yaml
/*.dat
/*.yml
/demo/keys
/demo/*.retry
/demo/venv

25
demo/README.rst Normal file
View File

@ -0,0 +1,25 @@
================
Demo Playbooks
================
The playbooks in this directory can be used to set up test cases for
data capture.
tiny
====
Using
=====
1. Create and activate a virtualenv.
::
$ virtualenv --python=python2.7 venv
$ source venv/bin/activate
2. Install the dependencies.
::
$ pip install -r requirements.txt

4
demo/ansible.cfg Normal file
View File

@ -0,0 +1,4 @@
[defaults]
host_key_checking = False
roles_path = ./roles
hostfile = hosts

1
demo/hosts Normal file
View File

@ -0,0 +1 @@
[cloud]

2
demo/requirements.txt Normal file
View File

@ -0,0 +1,2 @@
ansible>=2.2.1.0
shade>=1.14.1

125
demo/tiny.yml Normal file
View File

@ -0,0 +1,125 @@
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
# Set up the keypair, saving the values locally.
- name: Creating key pair downpour-demo
os_keypair:
state: present
name: downpour-demo
register: keypair
- name: Create local public key
local_action:
module: copy
content: "{{ keypair.key.public_key }}"
dest: "{{ inventory_dir }}/keys/{{ keypair.key.name }}.pub"
mode: 0600
when: "'private_key' in keypair.key" # only save key if we created a new key
- name: Create local private key
local_action:
module: copy
content: "{{ keypair.key.private_key }}"
dest: "{{ inventory_dir }}/keys/{{ keypair.key.name }}"
mode: 0600
when: "'private_key' in keypair.key" # only save key if we created a new key
# Create a security group and the rules needed for the ports we'll
# be using.
- name: Create security group
os_security_group:
name: 'downpour-demo'
description: 'Demo group used for downpour'
- name: add ssh ingress rule
os_security_group_rule:
state: present
security_group: 'downpour-demo'
protocol: tcp
port_range_min: 22
port_range_max: 22
- name: add HTTPS/443 ingress rule
os_security_group_rule:
state: present
security_group: 'downpour-demo'
protocol: tcp
port_range_min: 443
port_range_max: 443
# Set up the server resources.
- name: create a volume to hold the demo files
os_volume:
state: present
wait: yes
size: 1
display_name: 'downpour-demo-tiny'
- name: launch VM
os_server:
name: 'downpour-demo-tiny'
state: present
wait: yes
auto_ip: yes
image: 'Ubuntu 16.04'
flavor: ds512M # use the devstack flavor
key_name: downpour-demo
network: private
boot_from_volume: no
security_groups:
- downpour-demo
volumes:
- 'downpour-demo-tiny'
register: server
- name: add the server to our ansible inventory
add_host: hostname="{{ server.server.public_v4 }}"
groups=cloud
ansible_ssh_user=ubuntu
ansible_ssh_private_key_file="{{inventory_dir}}/keys/{{keypair.key.name}}"
# Wait for the server to finish booting and become accessible.
- hosts: cloud
gather_facts: no
tasks:
- name: Wait for instance to finish booting
connection: local
wait_for:
host="{{ansible_ssh_host|default(inventory_hostname)}}"
search_regex=OpenSSH
port=22
delay=30
timeout=150
- name: Try to login to the instance
raw: "/bin/ls"
retries: 3
delay: 10
ignore_errors: true
# Make the new Ubuntu 16.04 compatible with Ansible.
- hosts: cloud
gather_facts: no
tasks:
- name: "Install python2.7 since Ubuntu 16.04 doesn't ship it"
raw: "sudo apt-get update -y && sudo apt-get install -y python2.7 aptitude"
retries: 5
delay: 10
# Give the extra volume a filesystem
- hosts: cloud
vars:
ansible_python_interpreter: /usr/bin/python2.7
# Create a filesystem on the attached volume. /dev/vdb
tasks:
- name: Create /opt filesystem
filesystem: fstype=ext4 dev=/dev/vdb
become: true
- name: Mount /opt filesystem
mount: name=/opt src=/dev/vdb fstype=ext4 state=mounted
become: true
- hosts: localhost
connection: local
gather_facts: no
tasks:
- debug:
msg: Server is ready for capture.