Molecule: Regression: default playbooks missing for LXD driver

Created on 12 Nov 2018  ยท  11Comments  ยท  Source: ansible-community/molecule

Issue Type

  • Bug report

Molecule and Ansible details

ansible 2.7.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/.virtualenvs/nix-ansible/lib/python3.7/site-packages/ansible
  executable location = /home/user/.virtualenvs/nix-ansible/bin/ansible
  python version = 3.7.1 (default, Nov  5 2018, 14:07:04) [GCC 8.2.1 20181011 (Red Hat 8.2.1-4)]
molecule, version 2.19.0

Molecule installation method (one of):

  • pip

Ansible installation method (one of):

  • pip

Detail any linters or test runners used:

Desired Behavior

After running molecule init role --role-name basic_server --driver-name lxd, there should be default playbooks as this:

basic_server
โ”œโ”€โ”€ defaults
โ”‚ย ย  โ””โ”€โ”€ main.yml
โ”œโ”€โ”€ handlers
โ”‚ย ย  โ””โ”€โ”€ main.yml
โ”œโ”€โ”€ meta
โ”‚ย ย  โ””โ”€โ”€ main.yml
โ”œโ”€โ”€ molecule
โ”‚ย ย  โ””โ”€โ”€ default
โ”‚ย ย      โ”œโ”€โ”€ tests
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ __pycache__
โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ test_default.cpython-37.pyc
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ test_default.py
โ”‚ย ย      โ”œโ”€โ”€ create.yml
โ”‚ย ย      โ”œโ”€โ”€ destroy.yml
โ”‚ย ย      โ”œโ”€โ”€ INSTALL.rst
โ”‚ย ย      โ”œโ”€โ”€ molecule.yml
โ”‚ย ย      โ”œโ”€โ”€ playbook.yml
โ”‚ย ย      โ””โ”€โ”€ prepare.yml
โ”œโ”€โ”€ tasks
โ”‚ย ย  โ””โ”€โ”€ main.yml
โ”œโ”€โ”€ vars
โ”‚ย ย  โ””โ”€โ”€ main.yml
โ””โ”€โ”€ README.md

9 directories, 14 files

This is working in molecule==2.17 from pip.

Actual Behaviour

Playbooks create.yml, destroy.yml and prepare.yml are missing.

basic_server
โ”œโ”€โ”€ defaults
โ”‚ย ย  โ””โ”€โ”€ main.yml
โ”œโ”€โ”€ handlers
โ”‚ย ย  โ””โ”€โ”€ main.yml
โ”œโ”€โ”€ meta
โ”‚ย ย  โ””โ”€โ”€ main.yml
โ”œโ”€โ”€ molecule
โ”‚ย ย  โ””โ”€โ”€ default
โ”‚ย ย      โ”œโ”€โ”€ tests
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ __pycache__
โ”‚ย ย      โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ test_default.cpython-37.pyc
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ test_default.py
โ”‚ย ย      โ”œโ”€โ”€ INSTALL.rst
โ”‚ย ย      โ”œโ”€โ”€ molecule.yml
โ”‚ย ย      โ””โ”€โ”€ playbook.yml
โ”œโ”€โ”€ tasks
โ”‚ย ย  โ””โ”€โ”€ main.yml
โ”œโ”€โ”€ vars
โ”‚ย ย  โ””โ”€โ”€ main.yml
โ””โ”€โ”€ README.md

9 directories, 11 files
bug help wanted

Most helpful comment

@webknjaz I finally understand the motive behind these changes. Therefore, I consider this closed, although from the documentation piece

The playbook loading order is:
provisioner.playbooks.$driver_name.$action
provisioner.playbooks.$action
bundled_playbook.$driver_name.$action

I am not sure where to look for the default file. (I know just because I found out from PR #1278 )

All 11 comments

You call it a regression. What was the last version this worked as expected?

This is working in molecule==2.17 from pip.

It looks like those files were removed via PR #1436.

After running molecule init role --role-name basic_server --driver-name lxd, there should be default playbooks as this

Nope ;)

Default playbooks are moved to molecule/provisioner/ansible/playbooks/<drivername>/ since Molecule V2. These playbooks are used unless you create a create.yml playbook in the scenario directory, this overrides the default create.yml in that directory.

For LXD I implemented this in the PR #1436 and it is available since Molecule v2.18.
This is the same behavior as Docker and Vagrant (and all the other when they get updated to the new standard).
This behavior has the advantage that patches to the playbook can be made upstream and you should not have to backport a ton of playbooks in your roles ๐Ÿ‘

But if you want to maintain these playbooks, just copy them to the scenario directory and the behavior is the same as Molecule <2.17

@webknjaz I try to keep updated with the Molecule issues but if needed tag me, especially LXD issues :)

Nope ;)

Why? If you keep those in the molecule resources, rather than a generated dir structure, the behavior may become unreproducible, because of Molecule upgrade and users would not expect such change of behavior.

Is this documented?

Is this documented?

Yeah somewhat. It was implemented in #1278 and the documentation is found under provisioner/ansible in the docs:

The playbook loading order is:

    provisioner.playbooks.$driver_name.$action
    provisioner.playbooks.$action
    bundled_playbook.$driver_name.$action

Why?

More then the above explanation by @retr0h in the PR I don't know.

I personally do not see that much of a problem as long as semver is correctly used. As I stated before for most users this resolves the whole problem of keeping all the playbooks in one place and DRY the roles. This without resulting in the use of submodules or gilt.
Not keeping the playbooks up to date could also result in errors since the cerberus validation of Mocule changes or even the module upstream in Ansible.

I am interested in the view of the others though @dj-wasabi @lwm @gundalow :)

fair enough

@HalisCz does the info provided by @wilmardo suit you? May we close the issue now?

@webknjaz I finally understand the motive behind these changes. Therefore, I consider this closed, although from the documentation piece

The playbook loading order is:
provisioner.playbooks.$driver_name.$action
provisioner.playbooks.$action
bundled_playbook.$driver_name.$action

I am not sure where to look for the default file. (I know just because I found out from PR #1278 )

Was this page helpful?
0 / 5 - 0 ratings