Search code examples
dockeransibledockerfilemolecule

How to customize molecule's docker image?


I'm using Molecule to test some Ansible roles. I would like to push some files to the docker image used for testing. For that purpose, I put my test file in the molecule folder and ADD/COPY commands are added to the Dockerfile.j2 file. My folder structure looks like this:

- ansible-role-foo/
  - molecule/
    - default/
      - Dockerfile.j2
      - myTestFile.txt
      - ...

The Dockerfile.j2:

# Molecule managed
...

RUN mkdir -p /my/path
COPY myTestFile.txt /my/path

When lauching molecule --debug converge, I get the following error:

COPY failed: stat /var/lib/docker/tmp/docker-builder266739241/myTestFile.txt: no such file or directory

I'm using molecule 2.18.1.

How to correctly include myTestFile.txt in the docker image, in the context of molecule?


Solution

  • /var/lib/docker/tmp/docker-builder266739241/myTestFile.txt Obviously, your question has the answer. You should put your text file in the mentioned directory and see if it passes. Otherwise you should try giving the full path where your text file is located. GetFileAttributesEx c:RUN: The system cannot find the file specified.