Perform Monitoring of MongoDB Replicaset using ansible

43 views
Skip to first unread message

Amit Kulkarni

unread,
Sep 14, 2023, 12:45:47 PM9/14/23
to Ansible Project
Hello All,

I need to monitor MongoDB replica set using Ansible, I have created below playbook, i need some guidance  on the same, if some one has done this before please help.
---
- name: check the MongoDB replicaset status
  hosts: mongodb1
  become: yes
  become_method: su
  tasks:
    - name: check for the status of MongoDB
      community.mongodb.mongodb_status:
        replica_set: rs0
        poll: 5
        interval: 10
        when: ansible_hostname == "mongodb1"
      register: rs_status

    - name: send email notification based on Replica set status
      mail:
        host: xxx.xxx.xxx.xxx
        port: xxxxxxxx
        sender: ''
        to: ''
        subject: 'Report for replicaset'
        body: ''
      delegate_to:
      when:  (rs_status != "PRIMARY" ) or (rs_status != "SECONDARY") or (rs_status != "ARBITER" )

Dick Visser

unread,
Sep 14, 2023, 3:45:32 PM9/14/23
to ansible...@googlegroups.com

Sent from Gmail Mobile


On Thu, 14 Sep 2023 at 18:45, Amit Kulkarni <amit1...@gmail.com> wrote:
Hello All,

I need to monitor MongoDB replica set using Ansible


How is this monitoring supposed to happen? I'm asking because ansible is a configuration management tool. Monitoring is usually done with monitoring tools.

I have created below playbook, i need some guidance  on the same

What is the problem/error you encounter? 



if some one has done this before please help.
---
- name: check the MongoDB replicaset status
  hosts: mongodb1
  become: yes
  become_method: su
  tasks:
    - name: check for the status of MongoDB
      community.mongodb.mongodb_status:
        replica_set: rs0
        poll: 5
        interval: 10
        when: ansible_hostname == "mongodb1"
      register: rs_status

    - name: send email notification based on Replica set status
      mail:
        host: xxx.xxx.xxx.xxx
        port: xxxxxxxx
        sender: ''
        to: ''
        subject: 'Report for replicaset'
        body: ''
      delegate_to:
      when:  (rs_status != "PRIMARY" ) or (rs_status != "SECONDARY") or (rs_status != "ARBITER" )

--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c85bc0f1-37c4-4df6-9157-97e77955b3a6n%40googlegroups.com.

Amit Kulkarni

unread,
Sep 14, 2023, 3:59:18 PM9/14/23
to ansible...@googlegroups.com
Hello Dick,

Thanks for the response.

We are trying to do monitoring with Splunk but as of now we are sure if we can query to the admin DB and get the output of command rs.status(), in splunk.

That's why I am thinking of having this playbook as an alternative arrangement.

I have not tested it yet but happy to get feedback on the  playbook, if it's looking allrite

Regards
Amit

Dick Visser

unread,
Sep 15, 2023, 3:42:37 AM9/15/23
to ansible...@googlegroups.com
I would not use ansible for this purpose at all, so I don't think it looks "allrite" :)
If you have actual errors/issues with running the playbook then we have something tangible.
I wonder why you have not even tested it...?

Reply all
Reply to author
Forward
0 new messages