Refactor fact configuration for service_type_data

The service_type_data was not working properly and errored out
with a traceback on exit_json from the module.

We can actually handle this in native Ansible without a module so
let's do that and also hint the user at the issue if a project happens
to use this role without being mapped in the service types.

Change-Id: Icdac2f5325a01748cdb8a830430b8f66a035d416
This commit is contained in:
David Moreau-Simard 2017-10-19 16:52:10 -04:00
parent abf7f312c4
commit e402697cbb
No known key found for this signature in database
GPG Key ID: 33A07694CBB71ECC
2 changed files with 11 additions and 56 deletions

View File

@ -1,44 +0,0 @@
# 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

@ -1,15 +1,14 @@
- name: Get service-types data file
get_url:
uri:
url: https://service-types.openstack.org/service-types.json
dest: /tmp
register: result
body_format: json
register: service_types
- name: Collect service type data for project
get_service_type_data:
project_name: "{{ zuul.project.short_name }}"
service_types_file: "{{ result.dest }}"
register: service_type_data
- name: Set service_type_data as a fact
set_fact:
service_type_data: service_type_data
- block:
- name: Set service_type_data fact
set_fact:
service_type_data: "{{ service_types['json']['primary_service_by_project'][zuul.project.short_name] }}"
rescue:
- name: Handle missing service type mapping
fail:
msg: "{{ zuul.project.short_name }} is not mapped in service types"