From f10650a24f8d895f8d2a2f917c0893e119c456fe Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Tue, 7 Feb 2017 22:48:09 +0000 Subject: [PATCH] add a simple playbook to launch an instance Start a demo playbook to launch an instance for capture. Signed-off-by: Doug Hellmann --- .gitignore | 3 + demo/README.rst | 25 +++++++++ demo/ansible.cfg | 4 ++ demo/hosts | 1 + demo/requirements.txt | 2 + demo/tiny.yml | 125 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 160 insertions(+) create mode 100644 demo/README.rst create mode 100644 demo/ansible.cfg create mode 100644 demo/hosts create mode 100644 demo/requirements.txt create mode 100644 demo/tiny.yml diff --git a/.gitignore b/.gitignore index 3114356..b709545 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,6 @@ releasenotes/build /clouds.yaml /*.dat /*.yml +/demo/keys +/demo/*.retry +/demo/venv diff --git a/demo/README.rst b/demo/README.rst new file mode 100644 index 0000000..3ae1c21 --- /dev/null +++ b/demo/README.rst @@ -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 diff --git a/demo/ansible.cfg b/demo/ansible.cfg new file mode 100644 index 0000000..9053b23 --- /dev/null +++ b/demo/ansible.cfg @@ -0,0 +1,4 @@ +[defaults] +host_key_checking = False +roles_path = ./roles +hostfile = hosts \ No newline at end of file diff --git a/demo/hosts b/demo/hosts new file mode 100644 index 0000000..1126342 --- /dev/null +++ b/demo/hosts @@ -0,0 +1 @@ +[cloud] diff --git a/demo/requirements.txt b/demo/requirements.txt new file mode 100644 index 0000000..da8c3cd --- /dev/null +++ b/demo/requirements.txt @@ -0,0 +1,2 @@ +ansible>=2.2.1.0 +shade>=1.14.1 diff --git a/demo/tiny.yml b/demo/tiny.yml new file mode 100644 index 0000000..f245471 --- /dev/null +++ b/demo/tiny.yml @@ -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.