Molecule: docker version of molecule not working.

Created on 21 Nov 2019  路  2Comments  路  Source: ansible-community/molecule


molecule --version

molecule, version 2.20.0.0a3.dev12

I am using it as a alias command that uses docker.

alias molecule='docker run --rm -it -v "$(pwd)":/tmp/$(basename "${PWD}"):ro -v /var/run/docker.sock:/var/run/docker.sock -w /tmp/$(basename "${PWD}") quay.io/ansible/molecule molecule'

Molecule installation method (one of):

Docker

Ansible installation method (one of):

Arch linux package management

Detail any linters or test runners used:

Desired Behavior

molecule init role --driver-name docker --role-name ansible-role

Creating a new role named ansible-role

Actual Behaviour

molecule init role --driver-name docker --role-name ansible-role

I only get output of

--> Initializing new role ansible-role...
Traceback (most recent call last):
File "/usr/local/bin/molecule", line 10, in
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 722, in __call__
return self.main(args, *kwargs)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, *ctx.params)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 535, in invoke
return callback(
args, *kwargs)
File "/usr/local/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, *
kwargs)
File "/usr/local/lib/python3.7/site-packages/molecule/command/init/role.py", line 131, in role
r.execute()
File "/usr/local/lib/python3.7/site-packages/molecule/command/init/role.py", line 64, in execute
self._process_templates('role', self._command_args, role_directory)
File "/usr/local/lib/python3.7/site-packages/molecule/command/init/base.py", line 61, in _process_templates
no_input=True,
File "/usr/local/lib/python3.7/site-packages/cookiecutter/main.py", line 94, in cookiecutter
output_dir=output_dir
File "/usr/local/lib/python3.7/site-packages/cookiecutter/generate.py", line 364, in generate_files
generate_file(project_dir, infile, context, env)
File "/usr/local/lib/python3.7/site-packages/cookiecutter/generate.py", line 176, in generate_file
with io.open(outfile, 'w', encoding='utf-8') as fh:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/molecule/ansible-role/README.md'

bug

All 2 comments

Do not report bugs before reproducing them with the code of the master branch!

This text was in the template for a reason.

@thepenguinthatwants in case you never figured this out (or for those searching for this like me) the issue is that Docker can't write files to the mounted path, because its mounted as read-only. You can fix this by removing the ":ro" in the first -v line. Hope this helps!

(notice that by default Docker will run, and therefore create new files, as root, so you should additionally create a user in the image that matches the UID of your local user so that you can use the command seamlessly)

Was this page helpful?
0 / 5 - 0 ratings