Repository: ansible/molecule

Issue #1234: Using a local Docker image
Created: 2018-04-06T10:43:08Z
Issue Type

Question

Molecule and Ansible details
Molecule 2.12.1
Ansible 2.5.0
Molecule installation method:

pip

Ansible installation method:

OS package

Question
I'm using Docker to run molecule.
I'm trying to run tests using a local image, but I seemingly can't. I have created an image "my-image".
$ docker images
REPOSITORY      TAG       IMAGE ID            CREATED             SIZE
... 
my-image        latest    b75e17a94136        About an hour ago   217MB
...

And in molecule.yml I have the following platforms (everything else is default):
platforms:
  - name: my-container
    image: my-image:latest

When I then run molecule test I get the error:
--> Action: 'create'
    
    PLAY [Create] ******************************************************************
    
    TASK [Log into a Docker registry] **********************************************
    skipping: [localhost] => (item=None) 
    
    TASK [Create Dockerfiles from image names] *************************************
    changed: [localhost] => (item=None)
    
    TASK [Discover local Docker images] ********************************************
    ok: [localhost] => (item=None)
    
    TASK [Build an Ansible compatible image] ***************************************
    failed: [localhost] (item=None) => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result", "changed": false}
    
    PLAY RECAP *********************************************************************
    localhost                  : ok=2    changed=1    unreachable=0    failed=1   

Running molecule --debug test provides a long error including "msg": "Error building molecule_local/my-image - code: None, message: pull access denied for my-image, repository does not exist or may require 'docker login', logs: [u'Step 1/2 : FROM my-image:latest', u'\\n']"
So seemingly it is trying to download the image, instead of using the local image. However, I can make it work this way: I go into create.yml, remove all tasks except for Create molecule instance(s) and Wait for instance(s) creation to complete, where I replace image: "molecule_local/{{ item.image }}" with image: "{{ item.image }}". This results in the following create.yml:
---
- name: Create
  hosts: localhost
  connection: local
  gather_facts: false
  no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
  tasks:
    - name: Create molecule instance(s)
      docker_container:
        name: "{{ item.name }}"
        hostname: "{{ item.name }}"
        image: "{{ item.image }}"
        state: started
        recreate: false
        log_driver: json-file
        command: "{{ item.command | default('bash -c \"while true; do sleep 10000; done\"') }}"
        privileged: "{{ item.privileged | default(omit) }}"
        volumes: "{{ item.volumes | default(omit) }}"
        capabilities: "{{ item.capabilities | default(omit) }}"
        exposed_ports: "{{ item.exposed_ports | default(omit) }}"
        published_ports: "{{ item.published_ports | default(omit) }}"
        ulimits: "{{ item.ulimits | default(omit) }}"
        networks: "{{ item.networks | default(omit) }}"
        dns_servers: "{{ item.dns_servers | default(omit) }}"
      register: server
      with_items: "{{ molecule_yml.platforms }}"
      async: 7200
      poll: 0

    - name: Wait for instance(s) creation to complete
      async_status:
        jid: "{{ item.ansible_job_id }}"
      register: docker_jobs
      until: docker_jobs.finished
      retries: 300
      with_items: "{{ server.results }}"

Now I can run molecule test and it works as intended: It creates an instance, runs the role, runs tests, and exits without errors.
It seems to me that it's supposed to work without modifying the create.yml in the way I did, so I wonder what I did wrong. How was I supposed to use a local Docker image?

Duplicate issue #1383: Failure to discover local Docker images
Created: 2018-07-11T17:53:28Z
Issue Type

Bug report

Molecule and Ansible details
ansible --version
ansible 2.6.1
  config file = None
  configured module search path = [u'/Users/jpereira/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14 (default, Mar 22 2018, 14:43:05) [GCC 4.2.1 Compatible 


molecule --version
molecule, version 2.16.0

Molecule installation method (one of):

pip

Ansible installation method (one of):

brew

Desired Behavior
Trying to run and ssh into a basic role created through molecule.
Actual Behaviour (Bug report only)
TASK [Discover local Docker images] ********************************************
    failed: [localhost] (item=None) => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result", "changed": false}
    fatal: [localhost]: FAILED! => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result", "changed": false}

I receive this error when I input molecule converge into terminal

Closing comment (2018-07-15T07:37:20Z): You're not giving a lot of info of what you're doing specifically, but based on the title I think this might be a duplicate of #1234 . In summary: In the create.yml playbook, which is used to create an instance, the docker_image module is used. Setting pull: false here would perhaps solve the issue.