Configure SNMP Using Ansible Playbook Linux Best Examples

In last ansible article i have explained How to Write your First Playbook without error’s. In this article i am going to explain HowTo configure SNMP Using Ansible Playbook. SNMP – Simple Network Monitoring Protocol which is used to monitor Servers, Network Devices and any devices which support SNMP. See SNMP Installation and configuration.

Configure SNMP Using Ansible Playbook

If you do not use ansible automation tool you have to login to each and every server and configure SNMP for monitoring manually. Doing manual job may require at least 5 minutes for host.

First time snmp installation. You have to place snmpd.conf file in http/web server to download standard configuration file. You can also use default configuration from ansible snmp module.

- hosts: all
  remote_user: ravi
  become: yes
  become_method: sudo
  gather_facts: yes

- name: Install snmp packages
 yum: name=net-snmp state=latest

- name: Enable snmp service
 service: name=snmpd enabled=yes
 notify: Restart snmpd

- name: Download snmpd config file
 dest: /tmp/snmpd.conf

copy: src=/tmp/snmpd.conf dest=/etc/snmp/snmpd.conf owner=root group=root mode=644
 notify: Restart snmpd

 - name: Restart snmpd
 action: service name=snmpd state=restarted

After SNMP Installation change community string

As per my requirement i have to change SNMP community string after successful configuration. Below is the ansible playbook i used and accomplished job successfully.

- hosts: all
 remote_user: ravi
 become: yes
 become_method: sudo
 - name: Insert New line
 path: /etc/snmp/snmpd.conf
 insertafter: "rocommunity"
 content: |
 rocommunity private

- name: Restart SNMPD Service
 action: service name=snmpd state=restarted
configure snmp using ansible playbook

configure snmp using ansible

Ansible-playbook output is below

[Thu Nov 16 03:21:08 ravi@arkit-ansible:/playbooks]$ ansible-playbook insertcontent.yaml

PLAY [asic] ***********************************************

TASK [Gathering Facts] ************************************
ok: []

TASK [Insert New line] ***********************************
changed: []

TASK [Restart SNMPD Service] *****************************
changed: []

to retry, use: --limit @/playbooks/insertcontent.retry

PLAY RECAP *********************************************** : ok=3 changed=2 unreachable=0 failed=0

That’s it about configure SNMP using Ansible playbook Linux.

Related Articles

Install and Configuration of Ansible-Virtual Environment

Getting Started with Automation Tool

Installation of Automation Tool in RHEL 7/Centos 7

Official Site

Thanks for your wonderful Support and Encouragement

Ravi Kumar Ankam

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

2 Responses

  1. archana rajpalem says:

    hello ,
    how can we do the same for windows ? i want to install snmp feature on windows using ansible .

Leave a Reply

Your email address will not be published. Required fields are marked *