tripleo-ansible/role-addition.yml
Kevin Carter 1cb8d44e0f
fix galaxy meta requirements
Also takes the opportunity to ignore "meta" directory from molecule
jobs. Since we apparently can't use "irrevelant_files" with "files",
we're using a negative look-ahead regexpi[1], to take all BUT "meta.*".

[1] https://www.regular-expressions.info/lookaround.html

NOTE: this patch also toggle tripleo-ansible-centos-8-role-addition to
non-voting in order to get this change merged. This job times out on a
regular basis, and prevents this needed patch to merge. Follow-up are
needed, for instance calling "pip-compile" as it's now done here:
https://review.opendev.org/c/openstack/tripleo-quickstart/+/807491

Closes-Bug: 1943965
Change-Id: I84d077c6daefdbeda4fda2d1f8fdd400c7437500
Signed-off-by: Kevin Carter <kecarter@redhat.com>
2021-09-21 08:53:45 -05:00

112 lines
4.5 KiB
YAML
Executable File

#!/usr/bin/env ansible-playbook
---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# 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.
- name: Create a new role for TripleO-Ansible
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Check for role name
fail:
msg: >-
The required variable `role_name` is undefined. Check your settings.
when:
- role_name is undefined
- name: Normalize the role name
set_fact:
_role_name: "{{ role_name | replace('-', '_' ) }}"
- name: Create role
command: >-
ansible-galaxy init
--role-skeleton=_skeleton_role_
--init-path=tripleo_ansible/roles {{ _role_name }}
args:
creates: "tripleo_ansible/roles/{{ _role_name }}"
- name: Read zuul molecule file
slurp:
src: zuul.d/molecule.yaml
register: molecule_yaml
- name: Create molecule entry
copy:
content: |-
# Managed via ./role-addition.yml, do not edit manually without testing that
# new role addition does not reformat it.
---
{% set items = molecule_yaml['content'] | b64decode | from_yaml %}
{% set job_index = [] %}
{% set new_job_name = "tripleo-ansible-centos-8-molecule-" ~ _role_name %}
{% for item in items %}
{% if 'project-template' in item %}
{% if item['project-template']['name'] == "tripleo-ansible-molecule-jobs" %}
{% if not (new_job_name in item['project-template']['check']['jobs']) %}
{% set _ = item['project-template']['check']['jobs'].append(new_job_name) %}
{% set check_jobs = (item['project-template']['check']['jobs'] | sort) %}
{% set _ = item['project-template']['check'].update({'jobs': check_jobs}) %}
{% endif %}
{% if not (new_job_name in item['project-template']['gate']['jobs']) %}
{% set _ = item['project-template']['gate']['jobs'].append(new_job_name) %}
{% set gate_jobs = (item['project-template']['gate']['jobs'] | sort) %}
{% set _ = item['project-template']['gate'].update({'jobs': gate_jobs}) %}
{% endif %}
{% if not (new_job_name in item['project-template']['periodic-weekly']['jobs']) %}
{% set _ = item['project-template']['periodic-weekly']['jobs'].append(new_job_name) %}
{% set periodic_jobs = (item['project-template']['periodic-weekly']['jobs'] | sort) %}
{% set _ = item['project-template']['periodic-weekly'].update({'jobs': periodic_jobs}) %}
{% endif %}
{% endif %}
{% else %}
{% if item['job']['name'] == new_job_name %}
{% set _ = job_index.append(new_job_name) %}
{% endif %}
{% endif %}
{% endfor %}
{% if (job_index | length) < 1 %}
{% set new_job = {
"name": new_job_name,
"parent": "tripleo-ansible-centos-8-base",
"files": [
"^tripleo_ansible/roles/" ~ _role_name ~ "/(?!meta).*"
],
"vars": {
"tripleo_role_name": _role_name
}
}
%}
{% set _ = items.append({"job": new_job}) %}
{% endif %}
{% set project = items.pop(0) %}
{% set sorted_jobs = items | sort(attribute='job.name') %}
{% set _ = sorted_jobs.insert(0, project) %}
{{ sorted_jobs | to_nice_yaml(indent=2, width=1337) }}
dest: zuul.d/molecule.yaml
- name: Create role documentation
copy:
content: |
{% set opening = 'Role - ' ~ _role_name %}
{{ '=' * (opening | length) }}
{{ opening }}
{{ '=' * (opening | length) }}
.. ansibleautoplugin::
:role: tripleo_ansible/roles/{{ _role_name }}
dest: "doc/source/roles/role-{{ _role_name }}.rst"