Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some roles can't be imported with their FQCN (dash forbidden) #75

Closed
jusstol opened this issue Sep 22, 2022 · 2 comments
Closed

some roles can't be imported with their FQCN (dash forbidden) #75

jusstol opened this issue Sep 22, 2022 · 2 comments

Comments

@jusstol
Copy link

jusstol commented Sep 22, 2022

the situation

I chose to install all tdp collections with ansible-galaxy (I'm using Ansible 2.11.11), as dependencies, which works fine.

In most cases I can import playbook from a collection with its FQCN name like this :

- import_playbook: tosit.tdp.meta.hdfs
# instead of : ansible_roles/collections/ansible_collections/tosit/tdp/playbooks/meta/hdfs.yml

And a role like this :

- hosts: all
  roles:
    - tosit.tdp.utils.user
# instead of ansible_roles/collections/ansible_collections/tosit/tdp/roles/utils/user

Or a specific task like this :

- hosts: all
  - tasks:
    - import_role: tosit.tdp.hdfs.client
      tasks_from: install

# instead of
# - hosts: all
#   - tasks:
#     - import_role: livraison/installation/ansible_roles/collections/ansible_collections/tosit/tdp/roles/hdfs/client
#       tasks_from: install

the problem

There are some roles defined in tdp-collection-extras that I cannot import because they all have the same error :

- hosts: all
  become: yes
  tasks:
    - name: Common setup and configuration accross all ansible hosts
      import_role:
        name: tosit.tdp_extra.ansible-tdp-common-actions

# leads to :
ERROR! the role 'ansible_roles/collections/ansible_collections/tosit/tdp_extra/roles/ansible-tdp-common-actions' was not found in [list of my ansible paths]

the cause

Roles names in collections must not contain dashes (-).

Here are some references from the latest Ansible documentation.

Role names are now limited to contain only lowercase alphanumeric characters, plus _ and start with an alpha character.

The directory name of the role is used as the role name. Therefore, the directory name must comply with the above role name rules. The collection import into Galaxy will fail if a role name does not comply with these rules.

In this example we have a standalone role called my-standalone-role.webapp to emulate a standalone role that contains dashes in the name (which is not valid in collections)

The dash - character is not valid for playbook names in collections.

the solution

Replace all dashes (-) with underscores (_) in roles names.
For example the folder ./roles/ansible-tdp-common-actions would be renamed ./roles/ansible_tdp_common_actions.

I tried this already and it works. With that minor needed update, tdp-collection-extras could be used as a functionning collection installed via ansible-galaxy.

@jusstol
Copy link
Author

jusstol commented Sep 22, 2022

I'm sorry it might be a duplicate of #62

@rpignolet
Copy link
Contributor

Close as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants