Search code examples
dockerunit-testingtestingansiblemolecule

Why Molecule is not able to start a docker container


I am using Molecule to test my ansible role. Before rebooting my server was working fine. However, after, When I run molecule create

It is skipping the create process: Skipping, instances already created. However, nothing is running:

(myenv)[root]# docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

When running molecule converge. I am getting this error:

TASK [Gathering Facts] *********************************************************

fatal: [test_instance]: UNREACHABLE! => {"changed": false, "msg": "Authentication or permission failure.
In some cases, you may have been able to authenticate and did not have permissions on the target directory. 

Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: 
( umask 77 && mkdir -p \"` echo ~/.ansible/tmp/ansible-tmp-1575033184.79-237504774558686 `\" && echo
ansible-tmp-1575033184.79-237504774558686=\"` echo ~/.ansible/tmp/ansible-tmp-1575033184.79-237504774558686 `\" ), 
exited with result 1", "unreachable": true} 

Any idea on how to solve this problem?


Solution

  • Your molecule instances are created in docker but they were stopped when your rebooted and were not restarted automatically. Molecule sees them as created but cannot access them as they are not running.

    You have 2 solutions to fix this problem.

    Restart the stopped instances

    1. find the relevant name(s) of the container(s) with docker ps -a
    2. restart the instance(s) with docker start <name>

    Restart from scratch

    You can simply run molecule destroy [-s scenarion_name]. This will cleanup the left over instances and you can start your tests from scratch after that.