# docker\_containers fact is empty when container already started

**URL:** <https://forum.ansible.com/t/docker-containers-fact-is-empty-when-container-already-started/20435>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [February 3, 2016, 11:58am UTC](https://forum.ansible.com/t/docker-containers-fact-is-empty-when-container-already-started/20435 "2016-02-03T11:58:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clement\_Prevost](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@Clement\_Prevost](https://forum.ansible.com/u/Clement_Prevost)\
**Post date:** [February 3, 2016, 11:58am UTC](https://forum.ansible.com/t/docker-containers-fact-is-empty-when-container-already-started/20435/1 "2016-02-03T11:58:10Z")

</div>

Hi all,

I’ve been trying the docker module as a way to provision containers for a local development environment.  
I’m facing some issues.

- I declare only one host in my inventory named docker-host
- I expect the docker module to build an ssh-enabled base image and start some containers
- I register these containers via add\_host
- I use these hosts on the rest of the playbook

This works well if those containers are not already started or if the requested container state is reloaded or restarted.  
But when I request the started state, the docker\_containers fact is empty.

- name: create docker containers  
hosts: docker-host  
tasks:

- name: “ensure base image is build”  
docker\_image: path=“docker/docker-build-ubuntu-sshd-services” name=“ubuntu/sshd-services” state=build

- name: “ensure webapp container is started”  
docker:  
name: webapp  
image: ubuntu/sshd-services  
state: started # here, if state is “reloaded”, everything works fine

- name: “add webapp container as app-web in inventory”  
add\_host: name=“app-web” groups=app-web,env-dev ansible\_ssh\_host=“{{ item.NetworkSettings.IPAddress }}” ansible\_ssh\_port=22 ansible\_ssh\_user=root ansible\_ssh\_pass=docker  
with\_items: docker\_containers

- name: “show docker containers fact”  
debug: var=docker\_containers

- name: Provision web server  
hosts: app-web  
roles:

- php

- …

Command output at the second run:

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“docker\_containers”:   
}

I couldn’t find any documentation about this docker\_containers fact, I just found it on [this post of this mailing list](https://groups.google.com/d/msg/ansible-project/hTRPDNkJiF8/SmsWkuycnkYJ).  
Am I on the wrong direction ?

Thanks for your help,

Regards

PS: more infos

- Python 2.7.6
- ansible-playbook 2.0.0.2
- Docker version 1.9.1, build a34a1d5

---

<div class="post-metadata">

**Author:** ![Greg\_DeKoenigsberg1](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@Greg\_DeKoenigsberg1](https://forum.ansible.com/u/Greg_DeKoenigsberg1)\
**Post date:** [February 5, 2016, 12:41am UTC](https://forum.ansible.com/t/docker-containers-fact-is-empty-when-container-already-started/20435/2 "2016-02-05T00:41:10Z")

</div>

So just curious: is there any reason you need to use "started" rather  
than "reloaded" there?

--g
