Browse Source

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>
Doug Hellmann 2 years ago
parent
commit
f10650a24f
6 changed files with 160 additions and 0 deletions
  1. 3
    0
      .gitignore
  2. 25
    0
      demo/README.rst
  3. 4
    0
      demo/ansible.cfg
  4. 1
    0
      demo/hosts
  5. 2
    0
      demo/requirements.txt
  6. 125
    0
      demo/tiny.yml

+ 3
- 0
.gitignore View File

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

+ 25
- 0
demo/README.rst View File

@@ -0,0 +1,25 @@
1
+================
2
+ Demo Playbooks
3
+================
4
+
5
+The playbooks in this directory can be used to set up test cases for
6
+data capture.
7
+
8
+tiny
9
+====
10
+
11
+Using
12
+=====
13
+
14
+1. Create and activate a virtualenv.
15
+
16
+  ::
17
+
18
+    $ virtualenv --python=python2.7 venv
19
+    $ source venv/bin/activate
20
+
21
+2. Install the dependencies.
22
+
23
+  ::
24
+
25
+    $ pip install -r requirements.txt

+ 4
- 0
demo/ansible.cfg View File

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

+ 1
- 0
demo/hosts View File

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

+ 2
- 0
demo/requirements.txt View File

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

+ 125
- 0
demo/tiny.yml View File

@@ -0,0 +1,125 @@
1
+---
2
+- hosts: localhost
3
+  connection: local
4
+  gather_facts: no
5
+  tasks:
6
+    # Set up the keypair, saving the values locally.
7
+    - name: Creating key pair downpour-demo
8
+      os_keypair:
9
+        state: present
10
+        name: downpour-demo
11
+      register: keypair
12
+    - name: Create local public key
13
+      local_action:
14
+        module: copy
15
+        content: "{{ keypair.key.public_key }}"
16
+        dest: "{{ inventory_dir }}/keys/{{ keypair.key.name }}.pub"
17
+        mode: 0600
18
+      when: "'private_key' in keypair.key"  # only save key if we created a new key
19
+    - name: Create local private key
20
+      local_action:
21
+        module: copy
22
+        content: "{{ keypair.key.private_key }}"
23
+        dest: "{{ inventory_dir }}/keys/{{ keypair.key.name }}"
24
+        mode: 0600
25
+      when: "'private_key' in keypair.key"  # only save key if we created a new key
26
+
27
+    # Create a security group and the rules needed for the ports we'll
28
+    # be using.
29
+    - name: Create security group
30
+      os_security_group:
31
+        name: 'downpour-demo'
32
+        description: 'Demo group used for downpour'
33
+    - name: add ssh ingress rule
34
+      os_security_group_rule:
35
+        state: present
36
+        security_group: 'downpour-demo'
37
+        protocol: tcp
38
+        port_range_min: 22
39
+        port_range_max: 22
40
+    - name: add HTTPS/443 ingress rule
41
+      os_security_group_rule:
42
+        state: present
43
+        security_group: 'downpour-demo'
44
+        protocol: tcp
45
+        port_range_min: 443
46
+        port_range_max: 443
47
+
48
+    # Set up the server resources.
49
+    - name: create a volume to hold the demo files
50
+      os_volume:
51
+        state: present
52
+        wait: yes
53
+        size: 1
54
+        display_name: 'downpour-demo-tiny'
55
+
56
+    - name: launch VM
57
+      os_server:
58
+        name: 'downpour-demo-tiny'
59
+        state: present
60
+        wait: yes
61
+        auto_ip: yes
62
+        image: 'Ubuntu 16.04'
63
+        flavor: ds512M  # use the devstack flavor
64
+        key_name: downpour-demo
65
+        network: private
66
+        boot_from_volume: no
67
+        security_groups:
68
+          - downpour-demo
69
+        volumes:
70
+          - 'downpour-demo-tiny'
71
+      register: server
72
+    - name: add the server to our ansible inventory
73
+      add_host: hostname="{{ server.server.public_v4 }}"
74
+                groups=cloud
75
+                ansible_ssh_user=ubuntu
76
+                ansible_ssh_private_key_file="{{inventory_dir}}/keys/{{keypair.key.name}}"
77
+
78
+# Wait for the server to finish booting and become accessible.
79
+- hosts: cloud
80
+  gather_facts: no
81
+  tasks:
82
+    - name: Wait for instance to finish booting
83
+      connection: local
84
+      wait_for:
85
+        host="{{ansible_ssh_host|default(inventory_hostname)}}"
86
+        search_regex=OpenSSH
87
+        port=22
88
+        delay=30
89
+        timeout=150
90
+    - name: Try to login to the instance
91
+      raw: "/bin/ls"
92
+      retries: 3
93
+      delay: 10
94
+      ignore_errors: true
95
+
96
+# Make the new Ubuntu 16.04 compatible with Ansible.
97
+- hosts: cloud
98
+  gather_facts: no
99
+  tasks:
100
+
101
+    - name: "Install python2.7 since Ubuntu 16.04 doesn't ship it"
102
+      raw: "sudo apt-get update -y && sudo apt-get install -y python2.7 aptitude"
103
+      retries: 5
104
+      delay: 10
105
+
106
+# Give the extra volume a filesystem
107
+- hosts: cloud
108
+  vars:
109
+    ansible_python_interpreter: /usr/bin/python2.7
110
+
111
+  # Create a filesystem on the attached volume. /dev/vdb
112
+  tasks:
113
+    - name: Create /opt filesystem
114
+      filesystem: fstype=ext4 dev=/dev/vdb
115
+      become: true
116
+    - name: Mount /opt filesystem
117
+      mount: name=/opt src=/dev/vdb fstype=ext4 state=mounted
118
+      become: true
119
+
120
+- hosts: localhost
121
+  connection: local
122
+  gather_facts: no
123
+  tasks:
124
+    - debug:
125
+        msg: Server is ready for capture.

Loading…
Cancel
Save