# Call 2nd playbook to run on host defined on variable of 1st playbook

**URL:** <https://forum.ansible.com/t/call-2nd-playbook-to-run-on-host-defined-on-variable-of-1st-playbook/35042>\
**Category:** Ansible Project\
**Created:** [April 23, 2021, 10:27am UTC](https://forum.ansible.com/t/call-2nd-playbook-to-run-on-host-defined-on-variable-of-1st-playbook/35042 "2021-04-23T10:27:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ricardo\_Esteves](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Ricardo\_Esteves](https://forum.ansible.com/u/Ricardo_Esteves)\
**Post date:** [April 23, 2021, 10:27am UTC](https://forum.ansible.com/t/call-2nd-playbook-to-run-on-host-defined-on-variable-of-1st-playbook/35042/1 "2021-04-23T10:27:20Z")

</div>

Hi,

i have a playbook that reads a csv file which as hostnames, and some other columns, and i would like for each line of this csv file to call another playbook to be run on the hostname that i read from the csv 1st column

But i’m getting this error: [localhost]: FAILED! =\> {“reason”: "conflicting action statements: hosts, tasks

test\_csv.yml:

- hosts: localhost  
connection: local  
gather\_facts: no  
tasks:
- name: Read csv  
read\_csv:  
path: /tmp/test\_csv.txt  
delimiter: ‘|’  
register: staticRoutes
- name: debug  
debug:  
msg: “{{ item.hostName }}|{{ item.iFace }}|{{ item.staticRoute }}”  
with\_items: “{{ staticRoutes.list }}”  
when: item.hostName.find(‘#’) != 0
- name: call whoami  
include\_tasks: test\_csv\_whoami.yml  
with\_items: “{{ staticRoutes.list }}”  
when: item.hostName.find(‘#’) != 0

test\_csv\_whoami.yml:

- hosts: “{{ item.hostName }}”  
tasks:
- name: whoami  
command: whoami  
register: out
- debug: msg=“{{ out.stdout\_lines }}”

Can someone help me understand what is wrong?

---

<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:** [April 23, 2021, 11:04am UTC](https://forum.ansible.com/t/call-2nd-playbook-to-run-on-host-defined-on-variable-of-1st-playbook/35042/2 "2021-04-23T11:04:07Z")

</div>

> Hi,
> 
> i have a playbook that reads a csv file which as hostnames, and some other columns, and i would like for each line of  
> this csv file to call another playbook to be run on the hostname that i

read from the csv 1st column

> But i'm getting this error: [localhost]: FAILED! =\> {"reason": "conflicting action statements: hosts, tasks
> 
> test\_csv.yml:  
> - hosts: localhost  
> connection: local  
> gather\_facts: no  
> tasks:  
> - name: Read csv  
> read\_csv:  
> path: /tmp/test\_csv.txt  
> delimiter: '|'  
> register: staticRoutes  
> - name: debug  
> debug:  
> msg: "{{ item.hostName }}|{{ item.iFace }}|{{ item.staticRoute }}"  
> with\_items: "{{ staticRoutes.list }}"  
> when: item.hostName.find('#') != 0  
> - name: call whoami  
> include\_tasks: test\_csv\_whoami.yml  
> with\_items: "{{ staticRoutes.list }}"  
> when: item.hostName.find('#') != 0
> 
> test\_csv\_whoami.yml:  
> - hosts: "{{ item.hostName }}"  
> tasks:  
> - name: whoami  
> command: whoami  
> register: out  
> - debug: msg="{{ out.stdout\_lines }}"
> 
> Can someone help me understand what is wrong?

You can't include a playbook with "include\_tasks".

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

---

<div class="post-metadata">

**Author:** ![Ricardo\_Esteves](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Ricardo\_Esteves](https://forum.ansible.com/u/Ricardo_Esteves)\
**Post date:** [April 23, 2021, 1:23pm UTC](https://forum.ansible.com/t/call-2nd-playbook-to-run-on-host-defined-on-variable-of-1st-playbook/35042/3 "2021-04-23T13:23:34Z")

</div>

Yes, thank you, i now fixed it by having only the task on the 2nd yml (the one i include with include\_task) and using the delegate\_to on that task to make it execute on each host i got from the csv file.
