ansible / molecule

Molecule aids in the development and testing of Ansible content: collections, playbooks and roles
https://ansible.readthedocs.io/projects/molecule/
MIT License
3.88k stars 662 forks source link

molecule init role fails to create standalone role #3629

Closed deogracia closed 2 years ago

deogracia commented 2 years ago

Issue Type

Molecule and Ansible details

ansible --version && molecule --version
ansible [core 2.13.2]
  config file = None
  configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/vagrant/venv/lib/python3.9/site-packages/ansible
  ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/vagrant/venv/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  jinja version = 3.1.2
  libyaml = True
molecule 4.0.1 using python 3.9 
    ansible:2.13.2
    delegated:4.0.1 from molecule
    docker:2.0.0 from molecule_docker requiring collections: community.docker>=3.0.0-a2

Molecule installation method:

Ansible installation method:

Detail any linters or test runners used:

Desired Behavior

molecule init role role_A should create role when ansible-galaxy init role_A

Actual Behaviour

ansible-galaxy init a-b-c
- Role a-b-c was created successfully
ansible-galaxy init a_b_c
- Role a_b_c was created successfully
molecule init role a_b_c
CRITICAL Outside collections you must mention role namespace like: molecule init role 'acme.myrole'. Be sure you use only lowercase characters and underlines. See https://galaxy.ansible.com/docs/contributing/creating_role.html
molecule init role a-b-c
CRITICAL Outside collections you must mention role namespace like: molecule init role 'acme.myrole'. Be sure you use only lowercase characters and underlines. See https://galaxy.ansible.com/docs/contributing/creating_role.html

Molecule debug's option doesn't help

molecule --debug init role a_b_c 
CRITICAL Outside collections you must mention role namespace like: molecule init role 'acme.myrole'. Be sure you use only lowercase characters and underlines. See https://galaxy.ansible.com/docs/contributing/creating_role.html
molecule --debug init role a-b-c 
CRITICAL Outside collections you must mention role namespace like: molecule init role 'acme.myrole'. Be sure you use only lowercase characters and underlines. See https://galaxy.ansible.com/docs/contributing/creating_role.html
zhan9san commented 2 years ago

@deogracia

It is by design.

role name

The underscore, '_', in role name is mentioned in creating_role role-names as below.

Role names are limited to lowercase word characters (i.e., a-z, 0-9) and ‘_’. No special characters are allowed, including ‘.’, ‘-‘, and space. During import, any ‘.’ and ‘-‘ characters contained in the repository name or rolename will be replaced with ‘’.

namespace

Generally, a namespace is required to init a role by molecule. Like acme in acme.myrole.

You can change acme to your Github username or an allowed name following namespace-limitations

The first time you log into Galaxy using your GitHub credentials a namespace is created for your GitHub username automatically. For name limiations view Namespace Limitations. To request additional namespaces view Requesting Additional Namespaces.

If it can address your issue, could you close it?

deogracia commented 2 years ago

Thanks for pointing me out this parts, @zhan9san

First, my role won't be on ansible Galaxy. I don't think the namespace parts is really important. What I really don't understand is if molecule use ansible-galaxy to create role, why, given the same input molecule fails. On Creating Role, there's no mention that namespace is mandatory. But in molecule it is..

And for me, who only produce standalone role (at least for now) , it's annoying to generate new role with ansible-galaxy + using manual steps to do the same job as molecule init role.

Am I completely off tracks ansible/molecule normal way?

zhan9san commented 2 years ago

Hi @deogracia

It is recommended to use FQCN for builtin actions, even though it is not uploaded to Ansible Galaxy.

If there is no 'namespace' defined in rolename's prefix, it may be included by my_new_role instead of acme.my_new_role, and ansible-lint is not happy with that.

Let me know if you have any concerns.

Reference: ansible-lint fqcn builts

deogracia commented 1 year ago

Thanks @zhan9san !I'm sorry I didn't answer before. I use now FQCN first.

markfaine commented 1 year ago

It also fails if you have more than one namespace prefixes, mine is nats.default.my_new_role This should work as far as I can tell.