tripleo-ansible/role-addition.yml
Kevin Carter 09b1805e5f Convert tox to native zuul
This change converts the TripleO-Ansible test process to using native zuul.
After a long discussion about the current test process [0] it has been
determined that most folks using tox do so on a local workstation and
would not expect the local system to be modified when envoked.

To ensure we're not creating a situation where a developer runs tox with a
job that may require modifications of the system the current test
structure has been replaced with a native zuul `base` job.

> This change opens the door for us to add tox jobs later which may be
  added in support of the native jobs we're running now.

> The test_json_error role was updated to set required configuration
  for that specific role, which was being passed in via tox before.

Documentation has been added to the contributing section to highlight
the role development process and how folks can test things locally using
a script which will mimic the zuul job runtime.

[0] - http://eavesdrop.openstack.org/irclogs/%23tripleo/latest.log.html#t2019-06-27T14:01:13

Change-Id: Ia1f3d479f3ac447d125169d08c78aaccfeacea3a
Signed-off-by: Kevin Carter <kecarter@redhat.com>
2019-07-06 02:31:06 +00:00

110 lines
3.7 KiB
YAML

---
# 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: 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: |-
---
{% set items = molecule_yaml['content'] | b64decode | from_yaml %}
{% set job_index = [] %}
{% set new_job_name = "tripleo-ansible-centos-7-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) %}
{% endif %}
{% if not (new_job_name in item['project-template']['gate']['jobs']) %}
{% set _ = item['project-template']['gate']['jobs'].append(new_job_name) %}
{% 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",
"files": [
"^tripleo_ansible/roles/" ~ role_name ~ "/.*"
],
"vars": {
"tripleo_role_name": role_name
}
}
%}
{% set _ = items.append({"job": new_job}) %}
{% endif %}
{{ items | 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) }}
This role provides for the following services:
* {{ role_name }}
Default variables
~~~~~~~~~~~~~~~~~
.. literalinclude:: ../../../tripleo_ansible/roles/{{ role_name }}/defaults/main.yml
:language: yaml
:start-after: under the License.
Example playbook
~~~~~~~~~~~~~~~~
.. literalinclude:: ../../../tripleo_ansible/roles/{{ role_name }}/molecule/default/playbook.yml
:language: yaml
:start-after: under the License.
dest: "doc/source/roles/role-{{ role_name }}.rst"