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

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?

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
        Racke

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.