trying to pass variable to hosts

I am trying to pass a variables to the hosts in a play

  • name: include vars
    hosts: localhost
    connection: local
    tasks:

  • include_vars:
    dir: ‘…/group_vars’
    depth: 1

  • name: debug
    hosts: localhost
    connection: local
    tasks:

  • debug: msg=“{{ kfkahost0 }}”

  • name: Create topic
    hosts: “{{ kfkahost0 }}”
    tasks:

- name: include vars

- include_vars: dir=“…/group_vars” depth=“1”

#dir: ‘…/group_vars’
#depth: 1

  • shell: ./app/bin/kafka/bin/kafka-topics.sh --zookeeper {{ zkhost0 }}:2181 --create --topic {{ topic }} --partitions {{ partition }} --replication-factor {{ rpfactor }}
    42,3 Bot

in the debug step i see the hostname comes out in the msg fine

but in the next play it says kfkahost0 is undefined.

Those variables are set on localhost , not kfkahost0.

Why don't you just put your kafka host in a group and use group_vars?

Use hostvars, like: {{ hostvars['localhost']['kfkahost0'] }}