# How to execute two tasks under a play ?

**URL:** <https://forum.ansible.com/t/how-to-execute-two-tasks-under-a-play/31412>\
**Category:** Ansible Project\
**Created:** [October 3, 2019, 12:48pm UTC](https://forum.ansible.com/t/how-to-execute-two-tasks-under-a-play/31412 "2019-10-03T12:48:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Easy\_King](https://avatars.discourse-cdn.com/v4/letter/e/c2a13f/32.png) [@Easy\_King](https://forum.ansible.com/u/Easy_King)\
**Post date:** [October 3, 2019, 12:48pm UTC](https://forum.ansible.com/t/how-to-execute-two-tasks-under-a-play/31412/1 "2019-10-03T12:48:04Z")

</div>

My requirement is to run two tasks i.e “Load Deployment1.” & “Load Deployment2.” in my Play 4.

Below is my playbook:

`

- name: Play 4  
hosts: localhost  
tasks:
- name: “Load Deployment1.”  
tags: deploy  
include\_vars:  
file: “{{ item }}”  
with\_fileglob:
- “vars/App\_\*.yaml”

tasks:

- name: “Load Deployment2.”  
local\_action: command ls -ltr checkrun.yml

`

Below is the Output :

> [WARNING]: While constructing a mapping from /app/axmw/Ansible/playbook/finacle\_deployment/checkrun.yml, line 1, column 3, found a duplicate dict key  
> (tasks). Using last defined value only.
> 
> PLAY [Play 4] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [localhost]  
> TASK [Load Deployment2.] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> changed: [localhost → localhost]  
> PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

As you can see in the output due to duplicate tasks it ignores the first first and only executes the second task.

How can I change my playbook code so that both the tasks can get executed ?

I dont know why is ansible considering the tasks as duplicate when they are different tasks doing different work? Can’t we have multiple tasks under one play ?

I’m confused. Please help.

Thank you.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [October 3, 2019, 1:40pm UTC](https://forum.ansible.com/t/how-to-execute-two-tasks-under-a-play/31412/2 "2019-10-03T13:40:16Z")

</div>

No. One play can't have 2 "tasks:" directives. Put "hosts:" directive infront  
of the "tasks:"

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Play 4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hosts: localhost  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: "Load Deployment1."  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Play 4 continue  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hosts: localhost  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: "Load Deployment2."  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...

Cheers,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [October 3, 2019, 1:44pm UTC](https://forum.ansible.com/t/how-to-execute-two-tasks-under-a-play/31412/3 "2019-10-03T13:44:23Z")

</div>

Is there a reason why single play would not work?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Play 4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hosts: localhost  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: "Load Deployment1."  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tags: deploy  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include\_vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file: "{{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_fileglob:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- "vars/App\_\*.yaml"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: "Load Deployment2."  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local\_action: command ls -ltr checkrun.yml

Cheers,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![scorp123](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@scorp123](https://forum.ansible.com/u/scorp123)\
**Post date:** [October 6, 2019, 4:37am UTC](https://forum.ansible.com/t/how-to-execute-two-tasks-under-a-play/31412/4 "2019-10-06T04:37:11Z")

</div>

Leave the 2nd “tasks” statement away. Easy fix.
