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:


---
- name: Add shards
hosts: localhost
connection: local
gather_facts: false
vars:
start_port: 10000
total_shards: 3
tasks:
- name: Add mongodb shards
community.mongodb.mongodb_shard:
login_user: admin
login_password: admin
shard: "localhost:{{ item|int + start_port }}"
state: present
with_sequence: start=0 end="{{ total_shards - 1 }}"




El mié, 20 oct 2021 a las 10:38, Hareesh Vn (<[email protected]>)
escribió:

>
> can you please help me changing below code as per your suggestion of
> with_sequence?
>
>   - name: "Creating the database"
>      command: "sh /tmp/add_shard.sh {{item}} {{mongo_user}}
> {{mongo_password}}"
>      register: mongo_db_shard_add
>      ignore_errors: true
>     with_items: "{{P_NODE}}"
>     when: ansible_default_ipv4_address ==== "{{item}}"
> On Wednesday, 20 October 2021 at 14:55:18 UTC+5:30 [email protected]
> wrote:
>
>> 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.
>>
>> On Wed, Oct 20, 2021, 08:02 Hareesh Vn <[email protected]> wrote:
>>
>>> Hi Team
>>>
>>> Below is problem description on which i need help.
>>>
>>> I am adding single mongo db shards by running below shell command --
>>> this is working fine to install on one server
>>>    - name: "Creating the database"
>>>      command: "sh /tmp/add_shard.sh {{item}} {{mongo_user}}
>>> {{mongo_password}}"
>>>      register: mongo_db_shard_add
>>>      ignore_errors: true
>>>     with_items: "{{P_NODE}}"
>>>     when: ansible_default_ipv4_address ==== "{{item}}"
>>>
>>> here my Question :
>>>
>>> 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"
>>>
>>>
>>> Thanks
>>> Hareesh
>>>
>>>
>>>
>>>
>>> --
>>> 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 [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/3a17346e-7abf-4cca-aa3a-a60445d2e380n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ansible-project/3a17346e-7abf-4cca-aa3a-a60445d2e380n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/1481ef9f-7760-49f0-a169-7b920f35cac0n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/1481ef9f-7760-49f0-a169-7b920f35cac0n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFtje5Pe5mmV%2B98K9phY_YEWdCAmnGSdhs82S9nBAHLjCB6_iw%40mail.gmail.com.

Reply via email to