Ansible安装Nagios插件

1.deploy_nagios_plugin.yml

---
- hosts: nagios
  become: yes
  become_method: sudo

  tasks:
    - name: Install dependent packages
      yum: name={{ item }} state=latest
      with_items:
        - xinetd
        - openssl-devel
        - gcc
        - gcc-c++
      tags: download

    - name: Create Nagios User
      shell: useradd -s /sbin/nologin nagios -M
      tags: adduser

    - name: Create DellOMSA User
      shell: useradd -s /sbin/nologin dellomsa -M
      tags: adduser     

    - name: Copy nagios and nrpe plugins
      copy: src=/root/nagios/package dest=/usr/local/nagios

    - name: Tar package
      shell: cd /usr/local/nagios/package/;tar -xf nagios-plugins-2.2.1.tar.gz;tar -xf nrpe-3.2.1.tar.gz
      tags: tar

    - name: Configure nagios plugin
      shell: ./configure --prefix=/usr/local/nagios --with-openssl
      args:
        chdir: /usr/local/nagios/package/nagios-plugins-2.2.1
          
    - name: Make nagios plugin
      shell: make all && make install
      args:
        chdir: /usr/local/nagios/package/nagios-plugins-2.2.1
        
    - name: Configure nrpe plugin
      shell: ./configure --prefix=/usr/local/nagios/
      args:
        chdir: /usr/local/nagios/package/nrpe-3.2.1   
      
    - name: Make nrpe plugin
      shell: make all && make install && make install-plugin && make install-daemon && make install-config && make install-inetd && make install-init
      args:
        chdir: /usr/local/nagios/package/nrpe-3.2.1         

    - name: Copy nrpe.cfg file
      copy:
        src: /root/nagios/file/nrpe.cfg
        dest: /usr/local/nagios/etc/nrpe.cfg
        mode: 0644
      notify: restart nrpe

    - name: Copy nrpe file
      copy:
        src: /root/nagios/file/nrpe
        dest: /etc/xinetd.d/nrpe
        mode: 0644
      notify: restart xinetd

    - name: Enable nrpe service
      shell: systemctl enable nrpe.service

  handlers:
     - name: restart nrpe
       service: name=nrpe state=restarted
     - name: restart xinetd
       service: name=xinetd state=restarted  


「 文章如果对你有帮助,请点个赞哦^^ 」 

2+