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: Id36a15da4cf83697250c81e1650a9639f590b87f
Signed-off-by: Kevin Carter <kecarter@redhat.com>
This commit is contained in:
Kevin Carter 2020-01-20 08:54:43 -06:00
parent b45d4c6d21
commit c3d86e2a93

View File

@ -26,13 +26,17 @@
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 }}
--init-path=tripleo_ansible/roles {{ _role_name }}
args:
creates: "tripleo_ansible/roles/{{ role_name }}"
creates: "tripleo_ansible/roles/{{ _role_name }}"
- name: Read zuul molecule file
slurp:
@ -45,7 +49,7 @@
---
{% set items = molecule_yaml['content'] | b64decode | from_yaml %}
{% set job_index = [] %}
{% set new_job_name = "tripleo-ansible-centos-7-molecule-" ~ role_name %}
{% 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" %}
@ -71,10 +75,10 @@
"name": new_job_name,
"parent": "tripleo-ansible-centos-7-base",
"files": [
"^tripleo_ansible/roles/" ~ role_name ~ "/.*"
"^tripleo_ansible/roles/" ~ _role_name ~ "/.*"
],
"vars": {
"tripleo_role_name": role_name
"tripleo_role_name": _role_name
}
}
%}
@ -89,11 +93,11 @@
- name: Create role documentation
copy:
content: |
{% set opening = 'Role - ' ~ role_name %}
{% 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"
:role: tripleo_ansible/roles/{{ _role_name }}
dest: "doc/source/roles/role-{{ _role_name }}.rst"