Why Molecule is not able to start a docker container
Asked Answered
B

1

7

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?

Bennink answered 29/11, 2019 at 13:40 Comment(1)
Side comment for those marking off-topic and/or down voting: molecule is a tool to test ansible roles once you have developed them. As a quick shortcut, it is comparable to pytest for python, or php_unit for php.... I do not see why such questions would be off-topic here unless it definitely gets totally to the OS side. In this particular case, it is a pure usage problem (of a tool related to development, which is on topic according to SO rules).Penitential
P
3

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.

Penitential answered 29/11, 2019 at 13:57 Comment(3)
@Aminovic did you happen to find a solution to this? I am using molecule with docker driver on debian bullseye within custom environment with pip install, I am getting the same exact failure and destroying and creating the molecule test instance doesn't help. Docker is complaining that the container is not running after receiving ansible EXEC commands. Running the container manually as expected just exits right after the run.Tipi
@JeromeWalters I'm 99.9999% sure your problem has nothing to do with the above. If your container exits right after start, it is probably running a command that exists (e.g. bash, echo "toto", ....). To have a container staying alive in the background, you need to launch a command that will keep it running (e.g. nginx, tail -f /dev/null, my-service). As you will understand from this very quick-n-dirty explanation, this has nothing to do with molecule itself but with your usage of Docker.Penitential
@Zeitounator, this appears to be the case, though the question is "why doesn't molecule start them?". According to molecule create --help the command is supposed to Use the provisioner to start the instances.Violone

© 2022 - 2024 — McMap. All rights reserved.