I am trying to run a script for multiple time using a loop.
The way I want it is
Script: /{{home}}/{{appUser}}/bin/trade_data_dnld.ksh {{ date }} {{ trade_id }}
Now my requirement is to run the same script for a hundred trade IDs and its not really possible to run the playbook hundred times.
I am looking for an option where I can create a variable called trade_id
(free text) and pass the trade_id
in a comma separated format.
The playbook should pick those trade IDs in the list and run it in loop for each one.
How can I achieve this?
You can achieve it this way
- shell: /{{home}}/{{appUser}}/bin/trade_data_dnld.ksh {{ date }} {{ item }}
with_items: "{{ trade_id.split(',') }}"
And pass the variable to the playbook using -e trade_id="dsdsd,sdsdsd,dsds"
in your ansible-playbook
command.
split
will create a list of values and the shell task will iterate over this list and will run each time with the corresponding value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With