# Docker and Ansible: running specific tasks on a dynamically defined host list

**URL:** <https://forum.ansible.com/t/docker-and-ansible-running-specific-tasks-on-a-dynamically-defined-host-list/19267>\
**Category:** Ansible Project\
**Created:** [September 15, 2015, 11:39am UTC](https://forum.ansible.com/t/docker-and-ansible-running-specific-tasks-on-a-dynamically-defined-host-list/19267 "2015-09-15T11:39:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kamesh\_Sampath](https://avatars.discourse-cdn.com/v4/letter/k/f17d59/32.png) [@Kamesh\_Sampath](https://forum.ansible.com/u/Kamesh_Sampath)\
**Post date:** [September 15, 2015, 11:39am UTC](https://forum.ansible.com/t/docker-and-ansible-running-specific-tasks-on-a-dynamically-defined-host-list/19267/1 "2015-09-15T11:39:41Z")

</div>

Hello,

I am running docker swarm with Ansible, my playbook deploys a docker image on specific node using swarm, post that deployment I want to execute certain Ansible tasks on the host where the image is deployed (still running from the same playbook role), as I am using consul as my backend I am able to retrieve the host(s) where the image is deployed and used “add\_host” to create a host group.

I don’t know how to trigger the tasks via “include” on that hosts. Any thoughts how to achieve that ?

Below are the references of the main.yml of the role and the include file.

Regards,  
Kamesh

**main.yml**

`
