Using docker_containers return value in a different role

Hi All,

I am running a role “run_docker_containers” which creates a series of docker containers using the docker module.

`

  • name: Run containers
    docker: state=present name={{ item }} ports=80 image=myimage command=‘blah’
    with_sequence: start=1 end=‘5’ format=mycontainer_%d
    `

The containers are created OK, and I can display the output of the module by using a debug statement (from the documentation examples) if I put the debug statement inside the role “run_docker_containers”.

`

  • debug: msg={{inventory_hostname}}:{{item}}
    with_items: docker_containers
    `

I am currently trying to pass the information returned by the docker module to a different role. The other role is part of setting up load balancing, so I am trying to get IP and port settings of the containers.

I have tried using the debug statement above inside “load_balance” but could not get it to display any information. Here is what the output looks like inside the other role:

`
[mytest.host] => (item=docker_containers) => {

“item”: “docker_containers”,

“msg”: “mytest.host:docker_containers”

}
`

Here is what the list of roles looks like:

`

  • hosts: testhosts
    roles:
  • run_docker_containers
  • load_balance
    `

Any ideas how I can pass the information between roles?

Thanks

Mitch

I think what you want to use is the set_fact module to set variables from your provisioning roles that you later recall when provisioning your LBs.

http://docs.ansible.com/set_fact_module.html