Now i want to run add mutiple shards on multiple servers (example: add 3 shards on each servers). So how to change above code?
Basically , i want to run below command repeatedly in loop for "n’ number of time where n=number of shards to be added.
Also i should pass ‘n’ as input while running playbook
command: “sh /tmp/add_shard.sh {{item}} {{mongo_user}} {{mongo_password}} {{n}}”
where “n” is number of shards to be created"
You can define a data structure, a dict for example containing number of shards per server an individual shard settings etc. Then just use with_sequence to iterate from 1 to length of the aforementioned shards list.
I would not run a shell script with the command module. You should use the script module instead. But ideally if you have the option use the mongodb_shard module.
This piece of code actually uses with_sequence to illustrate how to generate a sequence of numbers that will then used to populate port numbers dynamically: