summaryrefslogtreecommitdiff
path: root/openstack
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2015-03-26 19:11:37 +0000
committerRichard Ipsum <richardipsum@fastmail.co.uk>2015-04-10 20:17:45 +0100
commit1f87b1fe2fa926ac4cfa106bea5617ddd1e10a3f (patch)
tree14421dca7d66c8303365f24a909ec080bc64e4d4 /openstack
parent1c482cb9a2199daadc44c11581b88d284973e9c0 (diff)
downloaddefinitions-1f87b1fe2fa926ac4cfa106bea5617ddd1e10a3f.tar.gz
glance: Move setup scripts to Ansible.
Also change systemd units and configure extension to match this change
Diffstat (limited to 'openstack')
-rw-r--r--openstack/etc/systemd/system/openstack-glance-setup.service6
-rw-r--r--openstack/usr/share/openstack/glance.yml62
-rw-r--r--openstack/usr/share/openstack/openstack-glance-setup89
3 files changed, 64 insertions, 93 deletions
diff --git a/openstack/etc/systemd/system/openstack-glance-setup.service b/openstack/etc/systemd/system/openstack-glance-setup.service
index ee03c167..c00c520c 100644
--- a/openstack/etc/systemd/system/openstack-glance-setup.service
+++ b/openstack/etc/systemd/system/openstack-glance-setup.service
@@ -1,11 +1,9 @@
[Unit]
-Description=Run openstack-glance-setup (once)
+Description=Run glance-setup Ansible scripts
After=local-fs.target openstack-keystone-setup.service postgres-server.service
[Service]
-Type=oneshot
-ExecStart=/usr/share/openstack/openstack-glance-setup
-Restart=no
+ExecStart=/usr/bin/ansible-playbook -v -M /usr/share/ansible/ansible-openstack-modules -i /usr/share/openstack/hosts /usr/share/openstack/glance.yml
[Install]
WantedBy=multi-user.target
diff --git a/openstack/usr/share/openstack/glance.yml b/openstack/usr/share/openstack/glance.yml
new file mode 100644
index 00000000..3bf51471
--- /dev/null
+++ b/openstack/usr/share/openstack/glance.yml
@@ -0,0 +1,62 @@
+---
+- hosts: localhost
+ vars_files:
+ - "/etc/openstack/glance.conf"
+ tasks:
+ - name: Create the glance user.
+ user: name=glance comment="Openstack Glance Daemons" shell=/sbin/nologin home=/var/lib/glance
+
+ - name: Create the /var folders for glance
+ file: path={{ item }} state=directory owner=glance group=glance
+ with_items:
+ - /var/run/glance
+ - /var/lock/glance
+ - /var/log/glance
+ - /var/lib/glance
+ - /var/lib/glance/images
+ - /var/lib/glance/image-cache
+
+ - file: path=/etc/glance state=directory
+ - name: Add the configuration needed for glance in /etc/glance using templates
+ template: src=/usr/share/openstack/glance/{{ item }} dest=/etc/glance/{{ item }}
+ with_lines:
+ - (cd /usr/share/openstack/glance && find -type f)
+
+ - keystone_user: >
+ user={{ GLANCE_SERVICE_USER }}
+ password={{ GLANCE_SERVICE_PASSWORD }}
+ tenant=service
+ token={{ KEYSTONE_TEMPORARY_ADMIN_TOKEN }}
+
+ - keystone_user: >
+ role=admin
+ user={{ GLANCE_SERVICE_USER }}
+ tenant=service
+ token={{ KEYSTONE_TEMPORARY_ADMIN_TOKEN }}
+
+ - keystone_service: >
+ name=glance
+ type=image
+ description="Openstack Image Service"
+ publicurl=http://{{ CONTROLLER_HOST_ADDRESS }}:9292
+ internalurl=http://{{ CONTROLLER_HOST_ADDRESS }}:9292
+ adminurl=http://{{ CONTROLLER_HOST_ADDRESS }}:9292
+ region='regionOne'
+ token={{ KEYSTONE_TEMPORARY_ADMIN_TOKEN }}
+
+ - postgresql_user: name={{ GLANCE_DB_USER }} login_host={{ CONTROLLER_HOST_ADDRESS }} password={{ GLANCE_DB_PASSWORD }}
+ sudo: yes
+ sudo_user: glance
+ - postgresql_db: name=glance owner={{ GLANCE_DB_USER }} login_host={{ CONTROLLER_HOST_ADDRESS }}
+ sudo: yes
+ sudo_user: glance
+
+ - glance_manage: action=dbsync
+ sudo: yes
+ sudo_user: glance
+
+ - name: Enable and start openstack-glance service
+ service: name={{ item }} enabled=yes state=started
+ with_items:
+ - openstack-glance-api.service
+ - openstack-glance-registry.service
diff --git a/openstack/usr/share/openstack/openstack-glance-setup b/openstack/usr/share/openstack/openstack-glance-setup
deleted file mode 100644
index 1363a7b7..00000000
--- a/openstack/usr/share/openstack/openstack-glance-setup
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/bin/sh
-#
-# Copyright (C) 2014 Codethink Limited
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-set -e
-
-# Create required system users and groups
-getent group glance >/dev/null || groupadd -r --gid 164 glance
-getent passwd glance >/dev/null || \
- useradd --uid 164 -r -g glance -d /var/lib/glance -s /sbin/nologin \
- -c "OpenStack Glance Daemons" glance
-
-# Create required keystone tenants, users and roles
-export OS_SERVICE_TOKEN=##KEYSTONE_TEMPORARY_ADMIN_TOKEN##
-export OS_SERVICE_ENDPOINT='http://onenode:35357/v2.0'
-
-keystone user-create --name ##GLANCE_SERVICE_USER## --pass ##GLANCE_SERVICE_PASSWORD##
-keystone user-role-add --tenant service --user ##GLANCE_SERVICE_USER## --role admin
-
-keystone service-create --name glance --type image --description "OpenStack Image Service"
-keystone endpoint-create --service-id $(keystone service-list | awk '/ image / {print $2}') \
- --publicurl ##GLANCE_PUBLIC_URL## \
- --internalurl ##GLANCE_INTERNAL_URL## \
- --adminurl ##GLANCE_ADMIN_URL##
-
-# Create run directory for glance
-if [ ! -d /var/run/glance ]; then
- mkdir -p /var/run/glance
- chown -R glance:glance /var/run/glance
-fi
-
-# Create the lock directory for glance
-if [ ! -d /var/lock/glance ]; then
- mkdir -p /var/lock/glance
- chown -R glance:glance /var/lock/glance
-fi
-
-# Create the log directory for glance
-if [ ! -d /var/log/glance ]; then
- mkdir -p /var/log/glance
- chown -R glance:glance /var/log/glance
-fi
-
-# Setup the glance database
-if ! sudo -u postgres psql -lqt | grep -q glance; then
- # Create posgreSQL user
- sudo -u postgres createuser \
- --pwprompt --encrypted \
- --no-adduser --no-createdb \
- --no-password \
- ##GLANCE_DB_USER##
-
- sudo -u postgres createdb \
- --owner=##GLANCE_DB_USER## \
- glance
-
- sudo -u glance glance-manage db_sync
-fi
-
-chown -R glance:glance /var/lib/glance
-
-# Remove the one-shot setup service
-rm /etc/systemd/system/multi-user.target.wants/openstack-glance-setup.service
-
-# Start glance services
-systemctl start openstack-glance-api
-systemctl start openstack-glance-registry
-
-# Create the links to run glance services when system start next times.
-ln -s "/etc/systemd/system/openstack-glance-api.service" \
- "/etc/systemd/system/multi-user.target.wants/openstack-glance-api.service"
-
-ln -s "/etc/systemd/system/openstack-glance-registry.service" \
- "/etc/systemd/system/multi-user.target.wants/openstack-glance-registry.service"
-
-exit 0