7 Commits

13 changed files with 229 additions and 6 deletions

View File

@ -1,8 +1,42 @@
# hpc-cloud
This repository will contain playbooks to bring up openstack components inside docker containers.
This repository contains playbooks to bring up openstack components inside docker containers.
It makes use of ansible roles for the openstack components and the supporting infrastructure.
The following roles are installed.
### Openstack components.
* keystone
* glance-controller
* horizon
* neutron-controller
* nova-controller
* nova-compute
* cinder-controller
* cinder-storage
### Auxilary components:
* database (mariadb)
* rabbitmq (cluster of three nodes)
* memcached
## Getting started:
### Prerequisites:
* A cluster of servers to install the components on.
* The machines running nova-compute and neutron-controller need a separate interface for neutron to use.
* ubuntu 16.04 with python installed (usually already present).
* Access to the webhost12.service.rug.nl docker repository.
### Settings:
Passwords need be added to `secrets.yml.topol` and it needs to be saved as `secrets.yml`.
This can be done by running `./generate_secrets.py`.
Optionally, one can encrypt the secrtets by running `ansible-vault encrypt secrets.yml`.
### Secrets:
It makes use of ansible roles.
The roles can be set in the inventory file (hosts)
To bring up one role, for instance keystone, use:

9
cinder-controller.yml Normal file
View File

@ -0,0 +1,9 @@
---
- hosts: all
name: Dummy to gather facts
tasks: []
- hosts: cinder-controller
become: True
roles:
- cinder-controller

9
cinder-storage.yml Normal file
View File

@ -0,0 +1,9 @@
---
- hosts: all
name: Dummy to gather facts
tasks: []
- hosts: cinder-storage
become: True
roles:
- cinder-storage

33
generate_secrets.py Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env python
"""
Open the secrets.yml and replace all passwords.
Original is backed up.
"""
import random
import string
from subprocess import call
from yaml import load, dump
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
# length of generated passwords.
pass_length = 20
with open('secrets.yml.topol', 'r') as f:
data = load(f, Loader=Loader)
for key, value in data.iteritems():
data[key] = ''.join(
random.choice(string.ascii_letters + string.digits)
for _ in range(pass_length))
# Make numbered backups of the secrets file.
call(['cp', '--backup=numbered', 'secrets.yml', 'secrets.yml.bak'])
with open('secrets.yml', 'w') as f:
dump(data, f, Dumper=Dumper, default_flow_style=False)

6
hosts
View File

@ -39,5 +39,11 @@ openstack01-node01 provider_interface_name=ens192
[nova-controller]
openstack01-node03
[cinder-controller]
openstack01-node03
[cinder-storage]
openstack01-node01 storage_volume=/dev/loop0
[nova-compute]
openstack01-node04 provider_interface_name=dummy0

26
post-install.yml Normal file
View File

@ -0,0 +1,26 @@
---
- hosts: all
name: Dummy to gather facts
tasks: []
- hosts: keystone
become: True
vars_files:
- settings.yml
tasks:
- name: copy public key
copy:
content: "{{ rsa_pub }}"
dest: /srv/keystone/root/id_rsa.pub
- name: post install configuration
command: docker exec -i keystone.service bash -c "source /root/admin-openrc.sh && {{ item }}"
with_items:
- openstack network create --share --external --provider-physical-network provider --provider-network-type flat provider
- >
openstack subnet create --network provider
--allocation-pool start={{ allocation_pool['start'] }},end={{ allocation_pool['end'] }}
--dns-nameserver {{ dns_nameserver }} --gateway {{ gateway }} --subnet-range {{ subnet_range }} provider
- openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
- openstack keypair create --public-key /root/id_rsa.pub adminkey

View File

@ -13,6 +13,7 @@
-e "CINDER_PASSWORD={{ secrets['CINDER_PASSWORD'] }}"
-e "CINDER_USER=cinder"
-e "KEYSTONE_HOST={{ hostvars[groups['keystone'][0]]['ansible_default_ipv4']['address'] }}"
-e "MEMCACHED_HOST={{ hostvars[groups['memcached'][0]]['ansible_default_ipv4']['address'] }}"
-e "MYSQL_HOST={{ hostvars[groups['databases'][0]]['ansible_default_ipv4']['address'] }}"
-e "MYSQL_ROOT_PASSWORD={{ secrets['MYSQL_ROOT_PASSWORD'] }}"
-e "OS_PASSWORD={{ secrets['OS_PASSWORD'] }}"
@ -31,8 +32,8 @@
state: directory
mode: 0777
with_items:
- /srv/cinder
- /srv/cinder/root
- /srv/cinder-controller
- /srv/cinder-controller/root
- name: install service file.
template:
@ -48,7 +49,7 @@
command: >
/usr/bin/docker run --rm
{{ env_vars }}
-v /srv/cinder/root:/root \
-v /srv/cinder-controller/root:/root \
{{ docker_image }} /etc/bootstrap.sh
tags: bootstrap

View File

@ -10,7 +10,7 @@ ExecStartPre=-/usr/bin/docker kill %n
ExecStartPre=-/usr/bin/docker rm %n
ExecStart=/usr/bin/docker run --name %n \
{{ env_vars | replace('\n', '') }} \
-v /srv/glance/root:/root \
-v /srv/cinder-controller/root:/root \
-p 8776:8776 \
{{ docker_image }}

View File

@ -0,0 +1,61 @@
# Build and install a docker image for cinder.
---
- name: include secrets
include_vars:
file: ../../secrets.yml
name: secrets
- set_fact:
docker_image: webhost12.service.rug.nl/hpc/openstack-cinder-storage:latest
env_vars: >
-e "MY_IP={{ ansible_default_ipv4.address }}"
-e "CINDER_HOST={{ hostvars[groups['cinder-storage'][0]]['ansible_default_ipv4']['address'] }}"
-e "CINDER_PASSWORD={{ secrets['CINDER_PASSWORD'] }}"
-e "CINDER_USER=cinder"
-e "GLANCE_HOST={{ hostvars[groups['glance-controller'][0]]['ansible_default_ipv4']['address'] }}"
-e "KEYSTONE_HOST={{ hostvars[groups['keystone'][0]]['ansible_default_ipv4']['address'] }}"
-e "MYSQL_HOST={{ hostvars[groups['databases'][0]]['ansible_default_ipv4']['address'] }}"
-e "MYSQL_ROOT_PASSWORD={{ secrets['MYSQL_ROOT_PASSWORD'] }}"
-e "OS_PASSWORD={{ secrets['OS_PASSWORD'] }}"
-e "RABBIT_HOST={{ hostvars[groups['rabbitmq'][0]]['ansible_default_ipv4']['address'] }}"
-e "RABBIT_PASSWORD={{ secrets['RABBIT_PASSWORD'] }}"
-e "RABBIT_USER=openstack"
- name: pull docker image
docker_image:
name: "{{ docker_image }}"
tags: pull
- name: Make build and persistent directories
file:
path: "{{ item }}"
state: directory
mode: 0777
with_items:
- /srv/cinder-storage
- /srv/cinder-storage/root
- name: initial setup
command: >
/usr/bin/docker run --rm
--privileged
{{ env_vars }}
-v /srv/cinder-storage/root:/root \
-v "{{ storage_volume }}":/dev/cinder_storage_volume \
{{ docker_image }} /etc/bootstrap.sh
tags: bootstrap
- name: install service file.
template:
src: templates/cinder-storage.service
dest: /etc/systemd/system/cinder-storage.service
mode: 644
owner: root
group: root
- command: systemctl daemon-reload
- name: make sure service is started
systemd:
name: cinder-storage.service
state: restarted

View File

@ -0,0 +1,20 @@
[Unit]
Description=Openstack Glance Container
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker kill %n
ExecStartPre=-/usr/bin/docker rm %n
ExecStart=/usr/bin/docker run --name %n \
--privileged \
{{ env_vars | replace('\n', '') }} \
-v /srv/cinder-storage/root:/root \
-v "{{ storage_volume }}":/dev/cinder_storage_volume \
-p 8776:8776 \
{{ docker_image }}
[Install]
WantedBy=multi-user.target

11
secrets.yml.topol Normal file
View File

@ -0,0 +1,11 @@
---
GLANCE_PASSWORD:
METADATA_SECRET:
MYSQL_ROOT_PASSWORD:
NEUTRON_PASSWORD:
NOVA_PASSWORD:
NOVA_PLACEMENT_PASSWORD:
OS_PASSWORD: # Keystone admin password
OS_DEMO_PASSWORD: # Keystone demo user password
RABBIT_PASSWORD:
RABBITMQ_ERLANG_COOKIE:

12
settings.yml Normal file
View File

@ -0,0 +1,12 @@
---
- allocation_pool:
start: 172.23.128.50
end: 172.23.128.249
- dns_nameserver: 129.125.4.6
- gateway: 172.23.128.250
- subnet_range: 172.23.128.0/24
- rsa_pub: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDStPUPXkcu81onUm/le54JCu174yXJJDsthDr96Mv8irBVBWuy5FxnaASuDpmC4QE4s0UAIg1iq/SWrr8qdBQ4OVuYFiW0S7ZJvcoKr/40Wh+T5MeltGQfmkDp6kBsfaMSo6M4tF1c8i+XgOgxb4fxHYb8mFhseztRLx6McxJJJLB0nu+T12WQ01nl0XtwD+3EsZWfxRH0KA59VHZSe3Anc5z+Fm7WU+1Vzy6/pkiIhVReI1L6VVhZsIdSu3fQK6fHQcujtfuw6RKEpisZQqnxMUviWQ98yeQXHk6Nx840WCh3vvKveEAoC4Y/UEZa1TMe6PczfUaLjaidUkpulJsP egon@egon-pc

View File

@ -9,3 +9,4 @@
- include: neutron-controller.yml
- include: nova-compute.yml
- include: horizon.yml
- include: post-install.yml