系统环境:
CentOS Linux release 7.5.1804 (Core)
[root@v73 shelltest]# uname -a
Linux v73 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
nagios客户端和插件
nagios-plugins-1.4.16.tar.gz
nrpe-2.13.tar.gz
ansible脚本的内容
[root@v73 shelltest]# cat installnagios.yml
---
- hosts: "192.168.156.83"
tasks:
- name: installsofts
yum: name={{ item.softname }} state=present
with_items:
- softname: "gcc"
- softname: "gcc-c++"
- softname: "make"
- softname: "openssl"
- softname: "xinetd"
- softname: "openssl-devel"
- name: addnagiosgroup
group:
name: nagios
state: present
ignore_errors: yes
- name: addnagiosuser
user:
name: nagios
shell: /sbin/nologin
groups: nagios
ignore_errors: yes
- name: copysrc.tar.gz
copy:
src: "/tmp/nagios-plugins-1.4.16.tar.gz"
dest: "/tmp/nagios-plugins-1.4.16.tar.gz"
- name: del srctmpdir
file:
path: "/tmp/nagios-1.4.16"
state: absent
ignore_errors: yes
- name: create srctmpdir
file:
path: "/tmp/nagios-1.4.16"
state: directory
- name: unarchive files
unarchive:
src: "/tmp/nagios-plugins-1.4.16.tar.gz"
dest: "/tmp/nagios-1.4.16"
remote_src: yes
- name: sedstring
shell: "sed -i -e '/gets is a security/d' /tmp/nagios-1.4.16/nagios-plugins-1.4.16/gl/stdio.in.h"
- name: install nagios
shell: "cd /tmp/nagios-1.4.16/nagios-plugins-1.4.16 && ./configure --prefix=/usr/local/nagios && make && make install && chown nagios.nagios /usr/local/nagios && chown -R nagios.nagios /usr/local/nagios/libexec"
- name: copysrc.tar.gz
copy:
src: "/tmp/nrpe-2.13.tar.gz"
dest: "/tmp/nrpe-2.13.tar.gz"
- name: del srctmpdir
file:
path: "/tmp/nrpe-2.13"
state: absent
ignore_errors: yes
- name: create srctmpdir
file:
path: "/tmp/nrpe-2.13"
state: directory
- name: unarchive files
unarchive:
src: "/tmp/nrpe-2.13.tar.gz"
dest: "/tmp/nrpe-2.13"
remote_src: yes
- name: install nrpe
shell: "cd /tmp/nrpe-2.13/nrpe-2.13 && ./configure && make all && make install-plugin && make install-daemon && make install-daemon-config && make install-xinetd"
- name: copynrpe
copy:
src: "/tmp/nrpe"
dest: "/etc/xinetd.d/nrpe"
- name: editnrpe
lineinfile:
dest: "/etc/services"
state: present
regexp: 'nrpe 5666/tcp # nrpe'
line: "nrpe 5666/tcp # nrpe"
backup: yes
- name: addmoint devsda1
lineinfile:
dest: "/usr/local/nagios/etc/nrpe.cfg"
state: present
regexp: 'command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1'
line: "command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1"
backup: yes
- name: addmoint devsda2
lineinfile:
dest: "/usr/local/nagios/etc/nrpe.cfg"
state: present
regexp: 'command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2'
line: "command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2"
- name: startservice
shell: "service xinetd restart"
在批量部署使用过程中将IP地址替换为主机组,如果编译安装报错,检查系统环境或都依赖的软件,一般加入剧本yum安装都能解决