ansible-playbook 安装nagios插件

新建一个yml文件(nagios服务端IP:10.100.2.180),如下:
---
  - hosts: all
    vars_files:
      - vars.yml
    tasks:
      - name: setup program
        yum: name={{ item }} state=present
        with_items:
          - gcc
          - gcc-c++
          - make
          - openssl
          - openssl-devel
      - name: addgroup
        group:
          name: nagios
          state: present
      - name: adduser
        user:
          name: nagios
          shell: /sbin/nologin
          groups: nagios
      - name: copy program
        copy: "src={{ item.src }} dest={{ item.dest }}"
        with_items:
          - src: "/opt/nagios/nagios-plugins-2.1.1.tar.gz"
            dest: "/tmp/"
          - src: "/opt/nagios/nrped"
            dest: "/etc/init.d/nrped"
          - src: "/opt/nagios/nrpe-2.15.tar.gz"
            dest: "/tmp/"
      - name: tar files
        command: tar -zxvf /tmp/nrpe-2.15.tar.gz -C /tmp
      - name: tar naiogs
        command: tar -zxvf /tmp/nagios-plugins-2.1.1.tar.gz -C /tmp
      - name: install nagios
        shell: "/tmp/nagios-plugins-2.1.1/configure --with-nagios-user=nagios --with-nagios-group=nagios && make && make install"
      - name: install nrpe
        shell: /tmp/nrpe-2.15/configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl && make all && make install-plugin && make install-daemon && make install-daemon-config
      - name: make a service
        command: chmod +x /etc/init.d/nrped
      - name: set chkconfig
        shell: chkconfig --add nrped && chkconfig nrped on
      - name: copy cfg file
        copy: "src=/opt/nagios/nrpe.cfg dest=/usr/local/nagios/etc/nrpe.cfg"
      - name: start nrped
        service: name=nrped state=started
      - name: add firewalld rule
        shell: firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address=10.100.2.180/32 port port=5666 protocol=tcp accept'
        when: ansible_os_family == "RedHat" and ansible_distribution_major_version|int  >= 7
        notify: restart firewalld
      - name: add iptables rule
        shell: iptables -I INPUT -s 10.100.2.180/32 -p tcp --dport 5666 -j ACCEPT
        when: ansible_os_family == "RedHat" and ansible_distribution_major_version|int  <= 6
        notify: restart iptables
    handlers:
      - name: restart firewalld
        service: name=firewalld state=restarted
      - name: restart iptables
        service: name=iptables state=restarted

再创建一个sh脚本,如下:

#!/bin/bash
echo "please input the host name"
read name
#set -x
if  [ -z "$name" ] ;then
    echo "please input the host name! "
else
/usr/bin/ansible-playbook newserver.yml --limit $name
fi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值