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 vars: tasks: - 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 get_url: url: http://192.168.2.8/snmpd.conf dest: /tmp/snmpd.conf copy: src=/tmp/snmpd.conf dest=/etc/snmp/snmpd.conf owner=root group=root mode=644 notify: Restart snmpd handlers: - 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 tasks: - name: Insert New line blockinfile: path: /etc/snmp/snmpd.conf insertafter: "rocommunity" content: | rocommunity private 192.168.3.7 - name: Restart SNMPD Service action: service name=snmpd state=restarted
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: [192.168.2.6] TASK [Insert New line] *********************************** changed: [192.168.2.6] TASK [Restart SNMPD Service] ***************************** changed: [192.168.2.6] to retry, use: --limit @/playbooks/insertcontent.retry PLAY RECAP *********************************************** 192.168.2.6 : 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
Thanks for your wonderful Support and Encouragement