Add role to provice a service_type_data fact

We need to map from project name to service-type name from time to
time. The data is standard, so grab it from its published location
and use it.

Change-Id: Iea42ba981cee260cbccd0b1eb2705d3ad419bf20
This commit is contained in:
Monty Taylor 2017-10-15 09:54:00 -05:00 committed by Andreas Jaeger
parent ca16523952
commit 53ebdfcf70
3 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,6 @@
Set service_type facts for a given project
Sets a type ``service_type_data`` which contains the service information
for the current project as defined by the "service" definition in:
http://specs.openstack.org/openstack/service-types-authority/downloads/published-schema.json

View File

@ -0,0 +1,44 @@
# Copyright (C) 2017 Red Hat, Inc.
#
# 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.
import json
from ansible.module_utils.basic import AnsibleModule
def main():
module = AnsibleModule(
argument_spec=dict(
project_name=dict(type='str'),
service_types_file=dict(type='str'),
),
)
project_name = module.params['project_name']
service_types_file = module.params['service_types_file']
service_data = json.load(open(service_types_file, 'r'))
if project_name in service_data['primary_service_by_project']:
module.exit_json(
service_data['primary_service_by_project'][project_name])
else:
module.fail_json(
msg='Project {name} is not in the Service Types Authority'.format(
name=project_name))
if __name__ == '__main__':
main()

View File

@ -0,0 +1,15 @@
tasks:
- name: Get service-types data file
get_url:
url: https://service-types.openstack.org/service-types.json
dest: "{{ ansible_user_dir }}/service-types.json"
- name: Collect service type data for project
get_service_type_data:
project_name: "{{ zuul.project.short_name }}"
service_types_file: "{{ ansible_user_dir }}/service-types.json"
register: service_type_data
- name: Set service_type_data as a fact
set_fact:
service_type_data: service_type_data