From 3ac7da64d12c631def3640369998d292fd1a199f Mon Sep 17 00:00:00 2001 From: Sam Yaple Date: Wed, 17 Jun 2015 08:11:44 +0000 Subject: Add initial config function and keystone support Add set_configs function that implements the flow from the proposed ansible-multi spec. Move start.sh to config-internal.sh to preserve existing behaviour. config-externall.sh copies the appropriate configs in from the bind'd location and sets permissions and ownership appropriately. Partially Implements: blueprint ansible-multi Change-Id: I53fca0660451087f273fefc3c63e0d8cf1a2c096 --- ansible/group_vars/all.yml | 1 - ansible/library/merge_configs | 84 +++++++++++++++++++++++ ansible/roles/bootstrap.yml | 34 +++++++++ ansible/roles/config.yml | 24 +++++++ ansible/roles/keystone/defaults/main.yml | 42 ++++++++++++ ansible/roles/keystone/tasks/bootstrap.yml | 14 ++++ ansible/roles/keystone/tasks/config.yml | 16 +++++ ansible/roles/keystone/tasks/main.yml | 13 ++-- ansible/roles/keystone/tasks/register.yml | 12 ++++ ansible/roles/keystone/tasks/start.yml | 9 +++ ansible/roles/keystone/templates/keystone.conf.j2 | 13 ++++ ansible/roles/start.yml | 30 ++++++++ 12 files changed, 285 insertions(+), 7 deletions(-) delete mode 100644 ansible/group_vars/all.yml create mode 100644 ansible/library/merge_configs create mode 100644 ansible/roles/bootstrap.yml create mode 100644 ansible/roles/config.yml create mode 100644 ansible/roles/keystone/defaults/main.yml create mode 100644 ansible/roles/keystone/tasks/bootstrap.yml create mode 100644 ansible/roles/keystone/tasks/config.yml create mode 100644 ansible/roles/keystone/tasks/register.yml create mode 100644 ansible/roles/keystone/tasks/start.yml create mode 100644 ansible/roles/keystone/templates/keystone.conf.j2 create mode 100644 ansible/roles/start.yml (limited to 'ansible') diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml deleted file mode 100644 index 313d58c35..000000000 --- a/ansible/group_vars/all.yml +++ /dev/null @@ -1 +0,0 @@ -koalla_directory: "/usr/share/kolla" diff --git a/ansible/library/merge_configs b/ansible/library/merge_configs new file mode 100644 index 000000000..9991833aa --- /dev/null +++ b/ansible/library/merge_configs @@ -0,0 +1,84 @@ +#!/usr/bin/python + +# Copyright 2015 Sam Yaple +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +DOCUMENTATION = ''' +--- +module: merge_configs +short_description: Merge ini-style configs +description: + - ConfigParser is used to merge several ini-style configs into one +options: + dest: + description: + - The destination file name + required: True + type: str + sources: + description: + - A list of files on the destination node to merge together + default: None + required: True + type: str +author: Sam Yaple +''' + +EXAMPLES = ''' +Merge multiple configs: + +- hosts: database + tasks: + - name: Merge configs + merge_configs: + sources: + - "/tmp/config_1.cnf" + - "/tmp/config_2.cnf" + - "/tmp/config_3.cnf" + dest: + - "/etc/mysql/my.cnf" +''' + +import ConfigParser + +def main(): + module = AnsibleModule( + argument_spec = dict( + sources = dict(required=True, type='list'), + dest = dict(required=True, type='str'), + ) + ) + + try: + sources = module.params.pop('sources') + dest = module.params.pop('dest') + + config = ConfigParser.ConfigParser() + + for source_file in sources: + config.read(source_file) + + with open(dest, 'wb') as dest_file: + config.write(dest_file) + + module.exit_json(changed=True) + except Exception, e: + changed = True + module.exit_json(failed=True, changed=changed, msg=repr(e)) + + +# import module snippets +from ansible.module_utils.basic import * +if __name__ == '__main__': + main() diff --git a/ansible/roles/bootstrap.yml b/ansible/roles/bootstrap.yml new file mode 100644 index 000000000..cb5bfd7fd --- /dev/null +++ b/ansible/roles/bootstrap.yml @@ -0,0 +1,34 @@ +--- +- name: Creating database + mysql_db: + login_host: "{{ database_address }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ service_database_name }}" + register: database + run_once: True + +- name: Creating database user and setting permissions + mysql_user: + login_host: "{{ database_address }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ service_database_name }}" + password: "{{ service_database_password }}" + host: "%" + priv: "{{ service_database_name }}.*:ALL" + append_privs: "yes" + run_once: True + +- include: start.yml + vars: + run_once: True + when: database|changed + +- name: Cleaning up boostrap container + docker: + name: "{{ container_name }}" + image: "{{ container_image }}" + state: "absent" + run_once: True + when: database|changed diff --git a/ansible/roles/config.yml b/ansible/roles/config.yml new file mode 100644 index 000000000..a941e89ee --- /dev/null +++ b/ansible/roles/config.yml @@ -0,0 +1,24 @@ +--- +- name: Ensuring templates config directory exists + file: + path: "{{ node_templates_directory }}/{{ project_name }}" + state: "directory" + recurse: yes + +- name: Ensuring config directory exists + file: + path: "{{ node_config_directory }}/{{ project_name }}" + state: "directory" + +- name: Copying over config(s) + template: + src: "{{ item.0 }}" + dest: "{{ item.1 }}" + with_together: + - config_source + - config_template_dest + +- name: Merging the config files and saving to the final destination + merge_configs: + sources: "{{ config_template_dest }}" + dest: "{{ config_dest }}" diff --git a/ansible/roles/keystone/defaults/main.yml b/ansible/roles/keystone/defaults/main.yml new file mode 100644 index 000000000..d3b4f3cb1 --- /dev/null +++ b/ansible/roles/keystone/defaults/main.yml @@ -0,0 +1,42 @@ +--- +project_name: "keystone" + +#################### +# Database +#################### +keystone_database_name: "keystone" +keystone_database_user: "keystone" +keystone_database_address: "{{ kolla_internal_address }}" + +# Do not override "service_*" variables +service_database_name: "{{ keystone_database_name }}" +service_database_user: "{{ keystone_database_user }}" +service_database_password: "{{ keystone_database_password }}" + + +#################### +# Docker +#################### +docker_keystone_registry: "{{ docker_registry }}" +docker_keystone_namespace: "{{ docker_namespace }}" +kolla_keystone_base_distro: "{{ kolla_base_distro }}" +kolla_keystone_install_type: "{{ kolla_install_type }}" +kolla_keystone_container_name: "keystone" + +docker_keystone_image: "{{ docker_keystone_registry }}{{ docker_keystone_namespace }}/{{ kolla_keystone_base_distro }}-{{ kolla_keystone_install_type }}-{{ kolla_keystone_container_name }}" +docker_keystone_tag: "{{ openstack_release }}" +docker_keystone_image_full: "{{ docker_keystone_image }}:{{ docker_keystone_tag }}" + + +#################### +# Openstack +#################### +keystone_public_address: "{{ kolla_external_address }}" +keystone_admin_address: "{{ kolla_internal_address }}" +keystone_internal_address: "{{ kolla_internal_address }}" + +keystone_public_port: "5000" +keystone_admin_port: "35357" + +keystone_logging_verbose: "{{ openstack_logging_verbose }}" +keystone_logging_debug: "{{ openstack_logging_debug }}" diff --git a/ansible/roles/keystone/tasks/bootstrap.yml b/ansible/roles/keystone/tasks/bootstrap.yml new file mode 100644 index 000000000..c2bbf1a02 --- /dev/null +++ b/ansible/roles/keystone/tasks/bootstrap.yml @@ -0,0 +1,14 @@ +--- +# "detach: False" ensures we will be able to wait until the database bootstrap +# is finished. We can also check the exit code and catch errors if the database +# initialization does not successfully finish +- include: ../../bootstrap.yml + vars: + container_detach: False + container_environment: + BOOTSTRAP: + CONFIG_STRATEGY: "{{ config_strategy }}" + container_image: "{{ docker_keystone_image_full }}" + container_name: "bootstrap_keystone" + container_volumes: + - "{{ node_config_directory }}/keystone/:/opt/kolla/configs/keystone/:ro" diff --git a/ansible/roles/keystone/tasks/config.yml b/ansible/roles/keystone/tasks/config.yml new file mode 100644 index 000000000..6a6a12eac --- /dev/null +++ b/ansible/roles/keystone/tasks/config.yml @@ -0,0 +1,16 @@ +--- +- include: ../../config.yml + vars: + config_source: + - "roles/keystone/templates/keystone.conf.j2" + - "/etc/kolla/config/global.conf" + - "/etc/kolla/config/database.conf" + - "/etc/kolla/config/messaging.conf" + - "/etc/kolla/config/keystone.conf" + config_template_dest: + - "{{ node_templates_directory }}/keystone/keystone.conf_minimal" + - "{{ node_templates_directory }}/keystone/keystone.conf_global" + - "{{ node_templates_directory }}/keystone/keystone.conf_database" + - "{{ node_templates_directory }}/keystone/keystone.conf_messaging" + - "{{ node_templates_directory }}/keystone/keystone.conf_augment" + config_dest: "{{ node_config_directory }}/keystone/keystone.conf" diff --git a/ansible/roles/keystone/tasks/main.yml b/ansible/roles/keystone/tasks/main.yml index 29a7fef52..2821641c4 100644 --- a/ansible/roles/keystone/tasks/main.yml +++ b/ansible/roles/keystone/tasks/main.yml @@ -1,7 +1,8 @@ --- -- name: Bringing up keystone service(s) - docker_compose: - project_name: keystone - compose_file: "{{ koalla_directory }}/compose/keystone.yml" - command: up - no_recreate: true +- include: config.yml + +- include: bootstrap.yml + +- include: start.yml + +#- include: register.yml diff --git a/ansible/roles/keystone/tasks/register.yml b/ansible/roles/keystone/tasks/register.yml new file mode 100644 index 000000000..8ee20320b --- /dev/null +++ b/ansible/roles/keystone/tasks/register.yml @@ -0,0 +1,12 @@ +--- +# NB: Not an Attorney +# +# Upstream ansible will have all of the new modules we need based on +# the shade library. They are written, but the keystone modules haven't3 +# been merged yet. None of the modules will land before Ansible 2.0. +# +# These new modules will be relicensed using ASL2.0 as the result of a +# gentlemen's agreement that the Kolla authors will not alter the Shade code. +# This does not place additional restrictions on the license of this work. The +# relicense agreement is based upon trust, not something legally binding and +# has no binding impact on the license of Kolla.. diff --git a/ansible/roles/keystone/tasks/start.yml b/ansible/roles/keystone/tasks/start.yml new file mode 100644 index 000000000..a1d999ef5 --- /dev/null +++ b/ansible/roles/keystone/tasks/start.yml @@ -0,0 +1,9 @@ +--- +- include: ../../start.yml + vars: + container_environment: + CONFIG_STRATEGY: "{{ config_strategy }}" + container_image: "{{ docker_keystone_image_full }}" + container_name: "keystone" + container_volumes: + - "{{ node_config_directory }}/keystone/:/opt/kolla/configs/keystone/:ro" diff --git a/ansible/roles/keystone/templates/keystone.conf.j2 b/ansible/roles/keystone/templates/keystone.conf.j2 new file mode 100644 index 000000000..9dc45cb0a --- /dev/null +++ b/ansible/roles/keystone/templates/keystone.conf.j2 @@ -0,0 +1,13 @@ +[DEFAULT] +verbose = {{ keystone_logging_verbose }} +debug = {{ keystone_logging_debug }} + +bind_host = {{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }} + +admin_token = {{ keystone_admin_token }} + +public_endpoint = http://{{ keystone_public_address }}:{{ keystone_public_port }} +admin_endpoint = http://{{ keystone_admin_address }}:{{ keystone_admin_port }} + +[database] +connection = mysql://{{ keystone_database_user }}:{{ keystone_database_password }}@{{ keystone_database_address }}/{{ keystone_database_name }} diff --git a/ansible/roles/start.yml b/ansible/roles/start.yml new file mode 100644 index 000000000..44d9b0c67 --- /dev/null +++ b/ansible/roles/start.yml @@ -0,0 +1,30 @@ +--- +# Using "state: reloaded" will restart the container if a new image is +# pulled or the paramaters are modified. +# +# "pull: always" will _always_ pull the latest image. It registers a +# change when the image has changed, regardless of "state" +# +# Due to a bug in the ansible docker module it doesnt properly supply the +# docker_api_version from docker-py, so we specify it here. This will be +# removed when the bugfix makes it downstream + +- name: Starting the container + docker: + detach: "{{ container_detach | default('True') }}" + env: "{{ container_environment }}" + docker_api_version: "{{ docker_api_version }}" + image: "{{ container_image }}" + insecure_registry: "{{ docker_insecure_registry }}" + name: "{{ container_name }}" + net: host + password: "{{ docker_registry_password }}" + privileged: "{{ container_privileged | default('False') }}" + pull: "{{ docker_pull_policy }}" + registry: "{{ docker_registry }}" + restart_policy: "{{ docker_restart_policy }}" + restart_policy_retry: "{{ docker_restart_policy_retry }}" + state: reloaded + username: "{{ docker_registry_username }}" + volumes: "{{ container_volumes }}" + run_once: "{{ run_once | default('False') }}" -- cgit v1.2.3