Thank you very much for your answer. Now I get it fully.
Is there a way to append the docker_containers result in a dict after each
execution: I need all containers {IP,name} couple later in the execution?
Le mercredi 19 novembre 2014 02:22:52 UTC+1, tkuratomi a écrit :
>
> This has to do with the way that new facts are returned from ansible
> modules. Anytime a task is run, the module that is run by that task
> has an opportunity to return new facts in an _ansible_facts entry.
> This is usually a mapping of names to values that were determined
> during the module's run. Ansible on the controlling machine reads the
> data in _ansible_facts and adds the new facts to the global facts
> dictionary that is available to subsequent tasks. Ansible does not
> provide any automatic namespacing for the facts returned by tasks.
> That means that if two tasks return dicts that use some of the same
> keys in _ansible_facts then the values from the latest task to be run
> will overwrite the earlier ones.
>
> So to take three examples we have:
>
> tasks:
> - docker: name="cluster-data" hostname="{{ data_hostname }}"
> image="lgueye/cluster-data" state=present
> - docker: name="cluster-data" hostname="{{ index_hostname }}"
> image="lgueye/cluster-data" state=present
>
> In this example, we have two tasks calling the same module to do the
> same thing to different hostnames. The module is almost certainly
> going to return the same _ansible_facts dictionary entries for both
> calls which means only the latest one will be seen by subsequent
> tasks.
>
> tasks:
> - docker: image=df02bd73464a name=somename_{{item}}
> with_sequence: count={{ start_containers_count }}
>
> In this example, we are looping start_containers_count times and
> invoking the docker module each time with a slightly different name
> parameter. So even though it's not as apparent, it's doing the same
> thing as the above example.
>
> tasks:
> - docker: image=df02bd73464a count={{ start_containers_count }}
>
> Only in this example are we actually executing the docker module only
> a single time. We're telling the module that it is responsible for
> starting up start_countainr_count instances on its own. Since the
> module has all the information in its one invocation to start all of
> hte containers, it is able to return information about all of the
> containers that it started in its one run to the ansible controller so
> the facts are set so that you can see all of the ip and host
> information.
>
> Hope that explanation is helpful!
> -Toshio
>
> On Tue, Nov 18, 2014 at 3:41 PM, louis gueye <[email protected]
> <javascript:>> wrote:
> > Hi Patrick,
> >
> > Actually i don't know if it has anything to do with the "with_sequences"
> > clause. I have the following code
> >
> > docker: name="cluster-data" hostname="{{ data_hostname }}"
> > image="lgueye/cluster-data" state=present
> > .
> > .
> > .
> > docker: name="cluster-index" hostname="{{ index_hostname }}"
> > image="lgueye/cluster-index" state=present
> >
> > When I loop over the docker_containers dict, seeking for IP adresses, I
> only
> > get one IP adress.
> > I dumped the dict and It contains information only about the last
> running
> > container.
> >
> > I'm just providing information, unfortunately I I'm totally unable to
> > provide a fix right now. Sorry.
> >
> >
> > Le mercredi 16 avril 2014 23:41:04 UTC+2, Patrick Galbraith a écrit :
> >>
> >> Hi all!
> >>
> >> I have what I think is a simple question. It pertains to what is
> >> visible/available in the "docker_containers" dictionary when running a
> run
> >> book.
> >>
> >> Ok, so, what’s throwing me off is whether to use one of the following:
> >>
> >> - name launch containers
> >>
> >> docker: image=df02bd73464a count={{ start_containers_count }}
> >>
> >> Or
> >>
> >> - name launch containers
> >>
> >> docker: image=df02bd73464a name=somename_{{item}}
> >>
> >> with_sequence: count={{ start_containers_count }}
> >>
> >> It is the first snippet that works for doing this next task:
> >>
> >> - name: print container info
> >>
> >> debug: msg="{{item['NetworkSettings']['IPAddress']}}"
> >>
> >> with_items: docker_containers
> >>
> >> Why? Because the latter results in “docker_containers” only having the
> >> last container’s information (last container launched), whereas the
> former
> >> gives me all of them.
> >>
> >>
> >> It’s probably something really simple…
> >
> > --
> > 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 [email protected] <javascript:>.
> > To post to this group, send email to [email protected]
> <javascript:>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/ansible-project/3deba4c8-8a2b-42c5-ac91-a9e4db5aeb03%40googlegroups.com.
>
>
> > For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/a5040ff5-8246-4d5d-b9e0-466fa6f8112f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.