# Docker+ansible

**URL:** <https://forum.ansible.com/t/docker-ansible/31586>\
**Category:** Ansible Project\
**Created:** [November 1, 2019, 11:37am UTC](https://forum.ansible.com/t/docker-ansible/31586 "2019-11-01T11:37:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sunitha\_Iyer](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@Sunitha\_Iyer](https://forum.ansible.com/u/Sunitha_Iyer)\
**Post date:** [November 1, 2019, 11:37am UTC](https://forum.ansible.com/t/docker-ansible/31586/1 "2019-11-01T11:37:35Z")

</div>

Hi

Is it possible to run more than one docker compose files from ansible?

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [November 1, 2019, 10:05pm UTC](https://forum.ansible.com/t/docker-ansible/31586/2 "2019-11-01T22:05:54Z")

</div>

Hi,

> Is it possible to run more than one docker compose files from ansible?

what makes you think it is not possible?

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![Sunitha\_Iyer](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@Sunitha\_Iyer](https://forum.ansible.com/u/Sunitha_Iyer)\
**Post date:** [November 2, 2019, 11:28am UTC](https://forum.ansible.com/t/docker-ansible/31586/3 "2019-11-02T11:28:40Z")

</div>

Hi Felix

Thanks, I am struggling to find the syntax

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [November 2, 2019, 11:45am UTC](https://forum.ansible.com/t/docker-ansible/31586/4 "2019-11-02T11:45:51Z")

</div>

> Hi Felix
> 
> Thanks, I am struggling to find the syntax

Hello Sunitha,

search for "Ansible docker compose", this should provide enough examples to build upon.

For specific help, post your playbook and the output and explain why you did it that way.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Sunitha\_Iyer](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@Sunitha\_Iyer](https://forum.ansible.com/u/Sunitha_Iyer)\
**Post date:** [November 2, 2019, 12:23pm UTC](https://forum.ansible.com/t/docker-ansible/31586/5 "2019-11-02T12:23:32Z")

</div>

Hi stefan, below is the playbook,

One way is to find a master playbook and include the other playbooks whichever is required. suppose if i have 10 microservices and I will have 10 compose files and as a part of a bug fix I don’t need to deploy all of them may be 2 or 3 based on the defects. so I thought having 10 different play books for 10 compse files and run the required ones. If you have any better idea do suggest me please.

- name: Run a docker compose file  
hosts: dockerVM  
become: yes  
become\_method: su

tasks:

- set\_fact: compose\_dir=/root/DockercomposeFile

- name: create a directory  
file:  
path: “{{compose\_dir}}”  
state: directory

- name: copy docker compose file  
file:  
src: /root/DockerComposeFile  
dest: /root/DockerComposeFile  
mode: “0755”

- name: Run a docker compose file  
docker\_service:  
project\_src: “{{ compose\_dir }}”  
state: present  
build: no  
register:output

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [November 2, 2019, 12:40pm UTC](https://forum.ansible.com/t/docker-ansible/31586/6 "2019-11-02T12:40:36Z")

</div>

> Hi stefan, below is the playbook,
> 
> One way is to find a master playbook and include the other playbooks whichever is required. suppose if i have 10  
> microservices and I will have 10 compose files and as a part of a bug fix I don't need to deploy all of them may be 2 or  
> 3 based on the defects. so I thought having 10 different play books for 10 compse files and run the required ones. If  
> you have any better idea do suggest me please.

Hello Sunitha,

I strongly suggest to setup an Ansible role which includes the tasks below and apply it in a loop in the playbook.

Different playbooks complicate your setup and are harder to maintain. Settings which vary between your micro services  
can be kept in variables / inventory.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Sunitha\_Iyer](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@Sunitha\_Iyer](https://forum.ansible.com/u/Sunitha_Iyer)\
**Post date:** [November 2, 2019, 12:51pm UTC](https://forum.ansible.com/t/docker-ansible/31586/7 "2019-11-02T12:51:57Z")

</div>

thank you so much and I really appreciate it.

---

<div class="post-metadata">

**Author:** ![uday1kiran](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/uday1kiran/32/1552_2.png) [@uday1kiran](https://forum.ansible.com/u/uday1kiran)\
**Post date:** [November 3, 2019, 7:24am UTC](https://forum.ansible.com/t/docker-ansible/31586/8 "2019-11-03T07:24:35Z")

</div>

Hi all,

I am not able to set this.  
Can you please guide.

> **(attachments)**
>
> ![Screenshot_20191103-125328__01.jpg](https://us1.discourse-cdn.com/ansible/original/2X/5/5e0c7d1e86c0432e0d9a5fcdc11fc3525130d888.jpeg)
