Repository: ansible/molecule

Issue #3464: Allow configuration of install_local bool in prerun
Created: 2022-03-10T21:43:48Z
Issue Type

Bug report

Molecule and Ansible details
(ansible-2.12.x) [nubly@ansible_host test_role]$ ansible --version && molecule --version
ansible [core 2.12.3]
  config file = /home/nubly/Git/ansible/ansible.cfg
  configured module search path = ['/home/nubly/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/nubly/.venvs/ansible-2.12.x/lib/python3.9/site-packages/ansible
  ansible collection location = /home/nubly/Git/ansible/collections
  executable location = /home/nubly/.venvs/ansible-2.12.x/bin/ansible
  python version = 3.9.2 (default, Jan 19 2022, 12:26:41) [GCC 11.1.0]
  jinja version = 3.0.3
  libyaml = True
molecule 3.6.1 using python 3.9
    ansible:2.12.3
    delegated:3.6.1 from molecule
    podman:1.1.0 from molecule_podman requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
Molecule installation method:

pip

Ansible installation method:

pip

Detail any linters or test runners used:

molecule
ansible-lint
yamllint
flake8

Desired Behavior
No symlink being left within the roles dir post-molecule action. Perhaps by way of a configuration option, or a flag.
Actual Behaviour
(ansible-2.12.x) [nubly@ansible_host test_role]$ molecule dependency
INFO     default scenario test matrix: dependency
INFO     Performing prerun...
INFO     Set ANSIBLE_LIBRARY=/home/nubly/.cache/ansible-compat/b09132/modules:/home/nubly/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/nubly/.cache/ansible-compat/b09132/collections:/home/nubly/Git/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/nubly/.cache/ansible-compat/b09132/roles:/home/nubly/Git/ansible/roles/external:/home/nubly/Git/ansible/roles/internal:/home/nubly/.venvs/ansible-2.12.x/share/ansible/roles
INFO     Using /home/nubly/Git/ansible/roles/internal/test.test_role symlink to current repository in order to enable Ansible to find the role using its expected full name.
INFO     Running default > dependency
WARNING  Skipping, missing the requirements file.

(ansible-2.12.x) [nubly@ansible_host test_role]$ ls -l ../
total 0
drwxr-xr-x  7 nubly root 124 Mar  9 16:13 test_role
lrwxrwxrwx  1 nubly root  73 Mar 10 13:19 test.test_role -> /home/nubly/Git/ansible/roles/test_role
Misc Info
This was discussed a bit in issue #3404 and pull request #3409.
My ansible environment consists of a large amount of roles within the same directory.
All roles which I have developed only depend on other roles I have developed, and thus there really isn't a need for me to use a namespace as I also do not publish them to Galaxy. It's a bit silly for me to have to worry about Galaxy naming requirements when I will not publish anything from my environment to Galaxy.
Since the install_local boolean was hardcoded True within #3409, on every Molecule action in which the prerun takes place, Molecule is creating symlinks
to roles which are already installed in the ANSIBLE_ROLES_PATH as a result of the prepare_environment() function continuing past the install_local check and then calling _install_galaxy_role.
The _install_galaxy_role function is also the only reason I am using a namespace, as it exits with an error by default if my role names are not up to spec even though they don't have to be.
At first, I thought that I could change my role directory naming convention to $namespace.$role_name to prevent this, but then I was met with ansible-compat #97.
I still want to be able to install requirements from requirements.yml, and as such I am unable to explicitly disable the prerun. However, I'd like to be able to disable the Galaxy role installation steps as I know that my any/all roles needed in my roles are present in my roles path and able to be found, as setting the boolean within the code to False results in my tests still running as they should.
I'd like to be able to specify a flag from CLI or configuration option within molecule.yml or some other applicable file to allow the value of the install_local boolean to be configured within Molecule's prerun, thereby allowing configuration of the creation of these symlinks (and installation of Galaxy roles). There was a small amount of discussion on this on #3409.

Duplicate issue #3495: Can't get my role to run locally anymore (OSError: [Errno 22] Invalid argument)
Created: 2022-04-04T15:10:13Z
Issue Type

Bug report

Molecule and Ansible details
$ ansible --version && molecule --version
ansible [core 2.12.3]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/Users/jgeerling/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/jgeerling/Library/Python/3.8/lib/python/site-packages/ansible
  ansible collection location = /Users/jgeerling/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/jgeerling/Library/Python/3.8/bin/ansible
  python version = 3.8.9 (default, Feb 18 2022, 07:45:33) [Clang 13.1.6 (clang-1316.0.21.2)]
  jinja version = 3.0.3
  libyaml = False
molecule 3.6.1 using python 3.9 
    ansible:2.12.3
    delegated:3.6.1 from molecule
    docker:1.1.0 from molecule_docker requiring collections: community.docker>=1.9.1

Molecule installation method (one of):

pip

Ansible installation method (one of):

pip

Detail any linters or test runners used:
N/A, run locally on macOS 12.3.1
Desired Behavior
If I run molecule test inside one of my Ansible roles, I can run molecule test successfully.
Actual Behaviour
$ git clone https://github.com/geerlingguy/ansible-role-docker.git
$ molecule test
$ molecule test
INFO     default scenario test matrix: dependency, lint, cleanup, destroy, syntax, create, prepare, converge, idempotence, side_effect, verify, cleanup, destroy
INFO     Performing prerun...
INFO     Set ANSIBLE_LIBRARY=/Users/jgeerling/.cache/ansible-compat/320470/modules:/Users/jgeerling/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/Users/jgeerling/.cache/ansible-compat/320470/collections:/Users/jgeerling/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/Users/jgeerling/.cache/ansible-compat/320470/roles:/Users/jgeerling/Dropbox/VMs/roles
Traceback (most recent call last):
  File "/opt/homebrew/bin/molecule", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/homebrew/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/molecule/command/test.py", line 161, in test
    base.execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args)
  File "/opt/homebrew/lib/python3.9/site-packages/molecule/command/base.py", line 111, in execute_cmdline_scenarios
    scenario.config.runtime.prepare_environment(install_local=True)
  File "/opt/homebrew/lib/python3.9/site-packages/ansible_compat/runtime.py", line 334, in prepare_environment
    self._install_galaxy_role(self.project_dir, ignore_errors=True)
  File "/opt/homebrew/lib/python3.9/site-packages/ansible_compat/runtime.py", line 494, in _install_galaxy_role
    if not exists or os.readlink(link_path) != str(target):
OSError: [Errno 22] Invalid argument: '/Users/jgeerling/Dropbox/VMs/roles/geerlingguy.docker'

I have my global Ansible roles directory symlinked to /Users/jgeerling/Dropbox/VMs/roles for convenience:
$ ls -lah /etc/ansible/roles
lrwxr-xr-x  1 root  wheel    34B Mar 22 15:01 /etc/ansible/roles -> /Users/jgeerling/Dropbox/VMs/roles

And in my case, I have my roles checked out to directories matching the galaxy names (e.g. geerlingguy.docker insteaad of ansible-role-docker), but that doesn't seem to matter, as the same failure occurs if I check out the role into any directory on my system.

Closing comment (2022-04-08T03:13:59Z): This is related to #3464  and #3409 Fix prepare_environment call for role installs
In 3.6.1, install_local is set to True, and there will be a conflict mentioned before.
If the install_local is set to False, the symlink would not be created.
I'll try to fix it, but it may take some time.