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.
The input data is not a fixed list but can be any number of lines returned by the database and registered by variable “command_result” as below":
`
name: “Play 1”
hosts: localhost
tasks:
name: “Search DB”
command: > mysql --user=root --password=p@ssword deployment
–host=localhost -Ns -e “SELECT dest_ip,file_dets FROM deploy_dets WHERE num LIKE ‘{{ CR_Number }}’”
register: command_result
`