Notes on Molecule

Submitted by kentr on 02/25/2019, 18:02

Notes to self...

  • Including Ansible variables from the python test file won't interpolate variables that are defined in the same file.  

    For example, this won't work:

    wp_deploy_dir: "/root/wordpress"
    wp_install_dir: "{{ wp_deploy_dir }}/wordpress/web"

    While this does work:

    wp_deploy_dir: "/root/wordpress"
    wp_install_dir: "/root/wordpress/web"
  • ansible_env doesn't change with become.  However, the resulting shell environment variables do change, such as $HOME.
  • For faster development, it's possible to skip the dependency phase in converge by setting custom converge_sequence in molecule.yml.
  • It's possible to debug the tests by:
    1. Run molecule --debug verify to get the exact pytest command that was run and the value for MOLECULE_INVENTORY_FILE.
    2. Go into the scenario directory.
    3. Run the pytest command that you got from step 1, but preface it with a statement that sets MOLECULE_INVENTORY_FILE.
  • TravisCI has multiple time limits:
  • Molecule docker containers on MacOS are created with the default docker setup.  With Docker Desktop for Mac, this means that Docker—and therefore the molecule container—are running inside a hyperkit virtual machine.
    • To "log in" to the VM running the container, use the screen command to attach to an existing terminal session inside the machine:
      $ screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty

       

  • host.run() actually runs commands with the Ansible command module.  Variable interpolation does happen at this point, but the variables must be in the global Ansible runner namespace.

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

6 + 5 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.