Merge "Add role to provice a service_type_data fact"
This commit is contained in:
commit
21f1ac0aeb
6
roles/set-service-type-data-fact/README.rst
Normal file
6
roles/set-service-type-data-fact/README.rst
Normal 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
|
@ -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()
|
15
roles/set-service-type-data-fact/tasks/main.yaml
Normal file
15
roles/set-service-type-data-fact/tasks/main.yaml
Normal 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
|
Loading…
x
Reference in New Issue
Block a user