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.89k stars 664 forks source link

Dockerfile.j2 is not generated when creating new scenarios #3773

Open 0x4d4c opened 1 year ago

0x4d4c commented 1 year ago

Issue Type

Molecule and Ansible details

ansible [core 2.14.1]
  config file = None
  configured module search path = ['$HOME/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = $HOME/.virtualenvs/molecule/lib/python3.10/site-packages/ansible
  ansible collection location = $HOME/.ansible/collections:/usr/share/ansible/collections
  executable location = $HOME/.virtualenvs/molecule/bin/ansible
  python version = 3.10.6 (main, Nov  2 2022, 18:53:38) [GCC 11.3.0] ($HOME/.virtualenvs/molecule/bin/python)
  jinja version = 3.1.2
  libyaml = True
molecule 4.0.5.dev3 using python 3.10 
    ansible:2.14.1
    delegated:4.0.5.dev3 from molecule
    docker:2.1.0 from molecule_docker requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0

Molecule installation method (one of):

(I tried both, pip and directly from source.)

Ansible installation method:

Detail any linters or test runners used:

Desired Behavior

The documentation states that a Dockerfile.j2 template will be "generated at molecule init scenario-time when --driver-name is docker." This does not happen for me, when I use this command in a roles directory of a collection: molecule init scenario --driver-name docker --role-name somename or molecule init scenario --driver-name docker --role-name somename somescenario. I only get converge.yml, molecule.yml and verify.yml.

I think either the Dockerfile.j2 should be generated or the documentation should be adjusted. In the latter case, instead of stating that a template will be generated, an example template would be nice (as the one in the repo).

SamDecrock commented 1 year ago

Same here.

andycui66 commented 1 year ago

I am using 6.0.1. Seems like --driver-name is not processed. I tried with docker,podman,vagrant,ec2 they all create the exact same files.

zhan9san commented 1 year ago

@SamDecrock and @andycui66

There are two ways to use molecule.

  1. Use Ansible collection directly. The end users have to maintain this playbook in their own repo.
  2. Use molecule-plugins

feel free to leave your comments in #4019

gavinw6662 commented 8 months ago

I haven’t used molecule in a long time but I ran into this behavior today. It definitely used to work with molecule 3.0 and lower.

I stumbled upon the fact that the code for this is likely found in the molecule-plugins project rather than here. There, I was able to find the Dockerfile.j2 template which has all that you need to spin up a container and run it in rootless mode (don't forget to add the blurb from docs to the bottom of the file - that's still required).

Needless to say, I opted to pip uninstall molecule, the old molecule-docker, molecule-plugins, molecule-plugins[docker] and then reinstalled it all (minus the older molecule[docker] code as that's now replaced by molecule-plugins[docker]). That still did not work.

INFO     Initializing new scenario newblah...

PLAY [Create a new molecule scenario] ******************************************

TASK [Check if destination folder exists] **************************************
changed: [localhost]

TASK [Check if destination folder is empty] ************************************
ok: [localhost]

TASK [Fail if destination folder is not empty] *********************************
skipping: [localhost]

TASK [Expand templates] ********************************************************
skipping: [localhost] => (item=molecule/newblah/destroy.yml)
changed: [localhost] => (item=molecule/newblah/molecule.yml)
changed: [localhost] => (item=molecule/newblah/converge.yml)
skipping: [localhost] => (item=molecule/newblah/create.yml)

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

$ ls -lah ./molecule/newblah/
total 16
drwx------  4 128B Mar  6 07:48 .
drwx------  5  160B Mar  6 07:48 ..
-rw-r--r--  1    203B Mar  6 07:48 converge.yml
-rw-r--r--  1   124B Mar  6 07:48 molecule.yml

But, copying and pasting the Dockerfile.j2 from the previous link works like a charm.

transiient commented 8 months ago

I've also just hit this issue. I have a working ansible user install through pip3 with ansible-lint. Ran pip3 install --user molecule "molecule-plugins[docker]" to install both and unfortunately it's not creating the Dockerfile.j2 file.

Also just tested with a fresh install of Docker in case that was causing a problem, but not successful.

Spec/versions:

Ubuntu Server 22.04 64 bit
pip 24.0 from /home/ansible/.local/lib/python3.9/site-packages/pip (python 3.9)
Python 3.9.18
ansible [core 2.15.9]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible
  ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.18 (main, Aug 25 2023, 13:20:14) [GCC 11.4.0] (/usr/bin/python3.9)
  jinja version = 3.1.3
  libyaml = True