I have an ansible play that fetches multiline data from the database and registers it a variable "command_result"
command_result variable has has data like below. host6,host5\targ3 host4,host3\targ1 host1,host2,host5\targ2 ..... ..... I need to loop through each line of command_result. Pick the host list for example host6,host5 and execute shell script using shell module by passing respective argument string i.e arg3. Likewise, the second shell script should run on host4 & host3 and pass arg1 to the shell script. The final shell script hould run on host1, host2 & host5 and pass arg2 to the shell script. - name: Add hosts add_host: name: "{{ item.split('\t')[0] }}" file_dets: "{{ item.split('\t')[1] }}" ansible_host: localhost ansible_connection: local groups: dest_nodes with_items: "{{ command_result.stdout_lines }}" - hosts: dest_nodes gather_facts: false tasks: - debug: msg: Run the shell script with the arguments `{{ file_dets }}` here" This works fine when there is a single host in item.split('\t')[0] However, I do not know the approach when there are multiple hosts like host6,host5 for {{ item.split('\t')[0] }} -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ef6c8ef7-7462-4e05-8025-7d1f514329b7%40googlegroups.com.