
If the export instructions list a separate key for the server, use that key when creating the new instance. Change-Id: I11d3f24857bbd1017ca6f888a0173d9bff8e2402 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
146 lines
4.3 KiB
YAML
146 lines
4.3 KiB
YAML
---
|
|
- hosts: localhost
|
|
connection: local
|
|
gather_facts: no
|
|
tasks:
|
|
# Set up the keypair we will use with the server,
|
|
# 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
|
|
- name: Creating key pair downpour-demo2
|
|
os_keypair:
|
|
state: present
|
|
name: downpour-demo2
|
|
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: 'xenial-server-cloudimg-amd64-disk1'
|
|
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.
|