docker_containers fact is empty when container already started

46 views
Skip to first unread message

Clément Prévost

unread,
Feb 3, 2016, 9:18:35 AM2/3/16
to Ansible Project
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
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

Greg DeKoenigsberg

unread,
Feb 4, 2016, 7:41:21 PM2/4/16
to Ansible Project
So just curious: is there any reason you need to use "started" rather
than "reloaded" there?

--g
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/9f812248-4e7b-4943-966a-c4aa4f000a7f%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Greg DeKoenigsberg
Ansible Community Guy
Reply all
Reply to author
Forward
0 new messages