Normalize role names when generating roles

Roles can no longer have a "-" in them according to the upstream ansible
documentation[0]. This change ensures that we're no longer generating roles
that have a "-" within them. The role-addition.yml playbook will now
normalize the name and replace any "-" with an "_".

[0] https://docs.ansible.com/ansible/devel/dev_guide/developing_collections.html#roles-directory

Change-Id: Ib758906a08dd611589394c77c627510d667034e9
Signed-off-by: Kevin Carter <kecarter@redhat.com>
(cherry picked from commit 3e30472f23)
This commit is contained in:
Kevin Carter 2020-01-20 09:06:38 -06:00 committed by Gael Chamoulaud (Strider)
parent 9a000ab840
commit a4c7660a9b
No known key found for this signature in database
GPG Key ID: 4119D0305C651D66
1 changed files with 16 additions and 11 deletions

View File

@ -26,13 +26,17 @@
when: when:
- role_name is undefined - role_name is undefined
- name: Normalize the role name
set_fact:
_role_name: "{{ role_name | replace('-', '_' ) }}"
- name: Create role - name: Create role
command: >- command: >-
ansible-galaxy init ansible-galaxy init
--role-skeleton=_skeleton_role_ --role-skeleton=_skeleton_role_
--init-path=roles {{ role_name }} --init-path=tripleo_validations/roles/{{ _role_name }}
args: args:
creates: "roles/{{ role_name }}" creates: "tripleo_validations/roles/{{ _role_name }}"
- name: Read zuul molecule file - name: Read zuul molecule file
slurp: slurp:
@ -45,7 +49,7 @@
--- ---
{% set items = molecule_yaml['content'] | b64decode | from_yaml %} {% set items = molecule_yaml['content'] | b64decode | from_yaml %}
{% set job_index = [] %} {% set job_index = [] %}
{% set new_job_name = "tripleo-validations-centos-7-molecule-" ~ role_name %} {% set new_job_name = "tripleo-validations-centos-7-molecule-" ~ _role_name %}
{% for item in items %} {% for item in items %}
{% if 'project-template' in item %} {% if 'project-template' in item %}
{% if item['project-template']['name'] == "tripleo-validations-molecule-jobs" %} {% if item['project-template']['name'] == "tripleo-validations-molecule-jobs" %}
@ -67,12 +71,12 @@
"name": new_job_name, "name": new_job_name,
"parent": "tripleo-validations-centos-7-base", "parent": "tripleo-validations-centos-7-base",
"files": [ "files": [
"^roles/" ~ role_name ~ "/.*" "^tripleo_validations/roles/" ~ _role_name ~ "/.*"
], ],
"vars": { "vars": {
"tripleo_validations_role_name": role_name "tripleo_role_name": _role_name
} }
} }
%} %}
{% set _ = items.append({"job": new_job}) %} {% set _ = items.append({"job": new_job}) %}
{% endif %} {% endif %}
@ -100,10 +104,11 @@
- name: Create role documentation - name: Create role documentation
copy: copy:
content: | content: |
{{ '=' * (role_name | length) }} {% set opening = 'Role - ' ~ _role_name %}
{{ role_name }} {{ '=' * (opening | length) }}
{{ '=' * (role_name | length) }} {{ opening }}
{{ '=' * (opening | length) }}
.. ansibleautoplugin:: .. ansibleautoplugin::
:role: roles/{{ role_name }} :role: tripleo_validations/roles/{{ _role_name }}
dest: "doc/source/roles/role-{{ role_name }}.rst" dest: "doc/source/roles/role-{{ _role_name }}.rst"